Merge pull request #16 from PM2-IT21bWIN-ruiz-mach-krea/ErrorTesting_Andrin
Functional issues fixed Nr. #4,#3,#8
This commit is contained in:
commit
e0ca1c77bb
|
@ -86,6 +86,7 @@ public class ChatWindowController {
|
|||
return;
|
||||
}
|
||||
String messageString = messageField.getText().strip();
|
||||
messageField.clear();
|
||||
Matcher matcher = messagePattern.matcher(messageString);
|
||||
if (matcher.find()) {
|
||||
String receiver = matcher.group(1);
|
||||
|
|
|
@ -305,7 +305,7 @@ public class NetworkHandler {
|
|||
* @param data data object of type T to be submitted through the connection.
|
||||
* @throws IOException if an error occurs (e.g. connection interrupted while sending, ...)
|
||||
*/
|
||||
public void send(T data) throws IOException {
|
||||
public synchronized void send(T data) throws IOException {
|
||||
ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream());
|
||||
outputStream.writeObject(data);
|
||||
}
|
||||
|
|
|
@ -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