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;
|
return;
|
||||||
}
|
}
|
||||||
String messageString = messageField.getText().strip();
|
String messageString = messageField.getText().strip();
|
||||||
|
messageField.clear();
|
||||||
Matcher matcher = messagePattern.matcher(messageString);
|
Matcher matcher = messagePattern.matcher(messageString);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
String receiver = matcher.group(1);
|
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.
|
* @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, ...)
|
* @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());
|
ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream());
|
||||||
outputStream.writeObject(data);
|
outputStream.writeObject(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class Server {
|
||||||
while (true) {
|
while (true) {
|
||||||
NetworkHandler.NetworkConnection<String> connection = networkServer.waitForConnection();
|
NetworkHandler.NetworkConnection<String> connection = networkServer.waitForConnection();
|
||||||
ServerConnectionHandler connectionHandler = new ServerConnectionHandler(connection, connections);
|
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>",
|
System.out.println(String.format("Connected new Client %s with IP:Port <%s:%d>",
|
||||||
connectionHandler.getUserName(),
|
connectionHandler.getUserName(),
|
||||||
connection.getRemoteHost(),
|
connection.getRemoteHost(),
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static ch.zhaw.pm2.multichat.server.ServerConnectionHandler.State.*;
|
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 static final AtomicInteger connectionCounter = new AtomicInteger(0);
|
||||||
private final int connectionId = connectionCounter.incrementAndGet();
|
private final int connectionId = connectionCounter.incrementAndGet();
|
||||||
private final NetworkHandler.NetworkConnection<String> connection;
|
private final NetworkHandler.NetworkConnection<String> connection;
|
||||||
|
@ -33,6 +33,11 @@ public class ServerConnectionHandler {
|
||||||
private String userName = "Anonymous-"+connectionId;
|
private String userName = "Anonymous-"+connectionId;
|
||||||
private State state = NEW;
|
private State state = NEW;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
startReceiving();
|
||||||
|
}
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
NEW, CONNECTED, DISCONNECTED;
|
NEW, CONNECTED, DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue