Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
server
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
9731050
server
Commits
b154a549
Commit
b154a549
authored
Jun 03, 2019
by
9731050
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
frist commit
parent
30b4162a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
ClientHandler.java
src/ClientHandler.java
+32
-0
Server.java
src/Server.java
+19
-0
No files found.
src/ClientHandler.java
0 → 100644
View file @
b154a549
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
}
public
void
run
()
{
while
(
true
){
try
{
String
input
=
dataInputStream
.
readUTF
();
handleIncomingMessages
(
input
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
src/Server.java
0 → 100644
View file @
b154a549
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.util.ArrayList
;
public
class
Server
{
private
static
final
int
PORT
=
4321
;
private
ServerSocket
serverSocket
;
private
ArrayList
<
String
>
user
;
public
Server
()
throws
Exception
{
serverSocket
=
new
ServerSocket
(
PORT
);
user
=
new
ArrayList
<>();
while
(
true
)
{
Socket
client
=
serverSocket
.
accept
();
ClientHandler
clientHandler
=
new
ClientHandler
(
client
);
}
}
}
\ No newline at end of file
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