Commit b154a549 authored by 9731050's avatar 9731050

frist commit

parent 30b4162a
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();
}
}
}
}
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment