Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
Session10_NargesSalehi_9628055_Part2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9628055
Session10_NargesSalehi_9628055_Part2
Commits
1510f37d
Commit
1510f37d
authored
Jun 10, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add servr
parents
Pipeline
#5122
canceled with stages
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
0 deletions
+90
-0
Handler.class
out/production/server/Handler.class
+0
-0
server.kotlin_module
out/production/server/META-INF/server.kotlin_module
+0
-0
Server.class
out/production/server/Server.class
+0
-0
server.iml
server.iml
+12
-0
Handler.java
src/Handler.java
+44
-0
Server.java
src/Server.java
+34
-0
No files found.
out/production/server/Handler.class
0 → 100644
View file @
1510f37d
File added
out/production/server/META-INF/server.kotlin_module
0 → 100644
View file @
1510f37d
File added
out/production/server/Server.class
0 → 100644
View file @
1510f37d
File added
server.iml
0 → 100644
View file @
1510f37d
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
src/Handler.java
0 → 100644
View file @
1510f37d
import
java.io.*
;
import
java.net.Socket
;
public
class
Handler
implements
Runnable
{
public
Socket
socket
;
public
DataInputStream
streamIn
=
null
;
public
DataOutputStream
streamOut
=
null
;
public
Handler
(
Socket
socket
)
{
this
.
socket
=
socket
;
}
@Override
public
void
run
()
{
try
{
streamIn
=
new
DataInputStream
(
new
BufferedInputStream
(
socket
.
getInputStream
()));
boolean
done
=
false
;
String
line
=
""
;
while
(!
done
)
{
try
{
line
+=
streamIn
.
readUTF
();
System
.
out
.
println
(
line
);
if
(
line
.
contains
(
"bye"
))
{
done
=
true
;
break
;
}
}
catch
(
IOException
ioe
)
{
done
=
true
;
}
try
{
streamOut
=
new
DataOutputStream
(
new
BufferedOutputStream
(
socket
.
getOutputStream
()));
streamOut
.
writeUTF
(
line
);
streamOut
.
flush
();
}
catch
(
IOException
ioe
)
{
System
.
out
.
println
(
"Sending error: "
+
ioe
.
getMessage
());
}
}
}
catch
(
IOException
ioe
)
{
System
.
out
.
println
(
ioe
);
}
}
}
src/Server.java
0 → 100644
View file @
1510f37d
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
public
class
Server
{
public
static
ServerSocket
server
;
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Binding to port "
+
5001
+
", please wait ..."
);
try
{
server
=
new
ServerSocket
(
5001
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"Server started: "
+
server
);
while
(
true
)
{
System
.
out
.
println
(
"Waiting for a client ..."
);
Socket
socket
=
null
;
try
{
socket
=
server
.
accept
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"Client accepted: "
+
socket
);
Thread
thread
=
new
Thread
(
new
Handler
(
socket
),
"thread"
);
thread
.
start
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment