Commit b349963a authored by KGreg's avatar KGreg
Browse files

ConnectionLost mechanism

parent b7b8e32e
......@@ -87,7 +87,7 @@ public class LobbyActivity extends AppCompatActivity implements ServerConnection
discovering = false;
for (ServerModel server : servers) {
SendDisconnect(server);
SendConnectionLost(server);
}
for (Thread thread : threads) {
......@@ -318,7 +318,7 @@ public class LobbyActivity extends AppCompatActivity implements ServerConnection
//nem sikerült
}
break;
case "Disconnect":
case "ConnectionLost":
for (ServerModel server: servers) {
if(server.getSocket() == serverModel.getSocket())
{
......@@ -332,18 +332,8 @@ public class LobbyActivity extends AppCompatActivity implements ServerConnection
}
break;
case "-1":
for (ServerModel server: servers) {
if(server.getSocket() == serverModel.getSocket())
{
int position = servers.indexOf(serverModel);
updateConversationHandler.post(new updateUIThread(Operation.REMOVE_SERVER, serverModel));
servers.remove(serverModel);
serverModel.getSocket().close();
threads.remove(Thread.currentThread());
Thread.currentThread().interrupt();
}
}
case "Disconnect":
//
break;
default:
break;
......@@ -405,13 +395,13 @@ public class LobbyActivity extends AppCompatActivity implements ServerConnection
recyclerView.setAdapter(adapter);
}
private void SendDisconnect(ServerModel server)
private void SendConnectionLost(ServerModel server)
{
try {
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(server.getSocket().getOutputStream())), true);
out.println("Disconnect");
out.println("ConnectionLost");
out.close();
} catch (IOException e) {
......
......@@ -119,14 +119,14 @@ public class LobbyActivity extends AppCompatActivity {
registred = false;
for (ClientModel client : allclients) {
SendDisconnect(client);
SendConnectionLost(client);
}
/*
for (Thread thread : threads) {
thread.interrupt();
}
*/
}
super.onPause();
......@@ -266,7 +266,7 @@ public class LobbyActivity extends AppCompatActivity {
}
else
{
params[0] = "Disconnect";
params[0] = "ConnectionLost";
}
switch (params[0]) {
......@@ -293,12 +293,13 @@ public class LobbyActivity extends AppCompatActivity {
}
out.println("Connect##Ok!");
break;
case "Disconnect":
case "ConnectionLost":
for (ClientModel client : clients) {
if (client.getClientsocket() == clientSocket) {
int position = clients.indexOf(client);
updateConversationHandler.post(new updateUIThread(Operation.REMOVE_CLIENT, Integer.toString(position)));
clients.remove(client);
allclients.remove(client);
clientSocket.close();
threads.remove(Thread.currentThread());
Thread.currentThread().interrupt();
......@@ -307,6 +308,16 @@ public class LobbyActivity extends AppCompatActivity {
}
};
break;
case "Disconnect":
for (ClientModel client : clients) {
if (client.getClientsocket() == clientSocket) {
int position = clients.indexOf(client);
clients.remove(client);
updateConversationHandler.post(new updateUIThread(Operation.REMOVE_CLIENT, Integer.toString(position)));
break;
}
};
break;
default:
out.println("Unknown Message!");
......@@ -366,13 +377,13 @@ public class LobbyActivity extends AppCompatActivity {
recyclerView.setAdapter(adapter);
}
private void SendDisconnect(ClientModel client)
private void SendConnectionLost(ClientModel client)
{
try {
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(client.getClientsocket().getOutputStream())), true);
out.println("Disconnect");
out.println("ConnectionLost");
out.close();
} catch (IOException e) {
......
Supports Markdown
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