Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Lab11
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
9731087
Lab11
Commits
c96f69bf
Commit
c96f69bf
authored
May 26, 2019
by
9731087
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Main, Server & ClientHandler added
parent
6e8db573
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
ClientHandler.java
src/ClientHandler.java
+36
-0
Server.java
src/Server.java
+21
-0
No files found.
src/ClientHandler.java
0 → 100644
View file @
c96f69bf
import
java.io.DataInputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.net.Socket
;
public
class
ClientHandler
{
private
Socket
socket
;
private
DataOutputStream
dataOutputStream
;
private
DataInputStream
dataInputStream
;
public
ClientHandler
(
Socket
client
)
throws
Exception
{
if
(
client
==
null
)
throw
new
Exception
(
"client can't be null"
);
this
.
socket
=
client
;
dataOutputStream
=
new
DataOutputStream
(
client
.
getOutputStream
());
dataInputStream
=
new
DataInputStream
(
client
.
getInputStream
());
run
();
}
private
void
handleIncomingMessages
(
String
message
)
{
//TODO: implement this method
System
.
out
.
println
(
message
);
}
public
void
run
()
{
while
(
true
)
{
try
{
String
input
=
dataInputStream
.
readUTF
();
handleIncomingMessages
(
input
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
src/Server.java
0 → 100644
View file @
c96f69bf
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
public
class
Server
{
private
static
final
int
PORT
=
4321
;
private
ServerSocket
serverSocket
;
public
Server
()
throws
IOException
{
serverSocket
=
new
ServerSocket
(
PORT
);
while
(
true
)
{
Socket
client
=
serverSocket
.
accept
();
try
{
ClientHandler
clientHandler
=
new
ClientHandler
(
client
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
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