Make ServerConnectionHandler runnable => fixed multiple client connection to server
This commit is contained in:
parent
029e099f26
commit
5054224653
|
@ -67,7 +67,7 @@ public class Server {
|
|||
while (true) {
|
||||
NetworkHandler.NetworkConnection<String> connection = networkServer.waitForConnection();
|
||||
ServerConnectionHandler connectionHandler = new ServerConnectionHandler(connection, connections);
|
||||
connectionHandler.startReceiving();
|
||||
new Thread(connectionHandler).start();
|
||||
System.out.println(String.format("Connected new Client %s with IP:Port <%s:%d>",
|
||||
connectionHandler.getUserName(),
|
||||
connection.getRemoteHost(),
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
|
||||
import static ch.zhaw.pm2.multichat.server.ServerConnectionHandler.State.*;
|
||||
|
||||
public class ServerConnectionHandler {
|
||||
public class ServerConnectionHandler implements Runnable{
|
||||
private static final AtomicInteger connectionCounter = new AtomicInteger(0);
|
||||
private final int connectionId = connectionCounter.incrementAndGet();
|
||||
private final NetworkHandler.NetworkConnection<String> connection;
|
||||
|
@ -33,6 +33,11 @@ public class ServerConnectionHandler {
|
|||
private String userName = "Anonymous-"+connectionId;
|
||||
private State state = NEW;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
startReceiving();
|
||||
}
|
||||
|
||||
enum State {
|
||||
NEW, CONNECTED, DISCONNECTED;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue