Commit 958283aa authored by KGreg's avatar KGreg
Browse files

Server crash fix

parent 38660cc3
......@@ -156,6 +156,16 @@ public class LobbyActivity extends AppCompatActivity implements ServerConnection
// When the network service is no longer available.
// Internal bookkeeping code goes here.
Log.e(TAG, "service lost" + service);
//
for (ServerModel server: servers) {
if(server.getSocket().getInetAddress() == service.getHost())
{
servers.remove(server);
// TODO: 2018. 03. 16. //refresh list
}
}
}
@Override
......@@ -207,8 +217,6 @@ public class LobbyActivity extends AppCompatActivity implements ServerConnection
hostAddress = serviceInfo.getHost();
runOnUiThread(new Runnable() {
public void run() {
//txtip.setText(hostAddress.getHostAddress());
......
......@@ -149,11 +149,12 @@ public class LobbyActivity extends AppCompatActivity {
@Override
public void onServiceUnregistered(NsdServiceInfo serviceInfo) {
// Service has been unregistered. This only happens when you
// call
// NsdManager.unregisterService() and pass in this listener.
Log.d("TAG",
"Service Unregistered : " + serviceInfo.getServiceName());
}
@Override
......@@ -212,54 +213,74 @@ public class LobbyActivity extends AppCompatActivity {
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
String read = input.readLine();
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(clientSocket.getOutputStream())), true);
String params[] = read.split("##");
switch (params[0])
{
case "Hostname":
out.println("Hostname##"+HOSTNAME);
break;
case "Connect":
boolean van = false;
for (ClientModel client: clients) {
if(client.getClientsocket() == clientSocket) {
van = true;
break;
if(clientSocket.isConnected()) {
String read = input.readLine();
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(clientSocket.getOutputStream())), true);
String params[] = {"Unknown"};
if (read != null) {
params = read.split("##");
}
else
{
params[0] = "Disconnect";
}
switch (params[0]) {
case "Hostname":
out.println("Hostname##" + HOSTNAME);
break;
case "Connect":
boolean van = false;
for (ClientModel client : clients) {
if (client.getClientsocket() == clientSocket) {
van = true;
break;
}
}
}
if(!van) {
String cname = "Unknown";
if (params.length >1) {
cname = params[1];
if (!van) {
String cname = "Unknown";
if (params.length > 1) {
cname = params[1];
}
clients.add(new ClientModel(cname, clientSocket));
updateConversationHandler.post(new updateUIThread(cname));
}
clients.add(new ClientModel(cname, clientSocket));
updateConversationHandler.post(new updateUIThread(cname));
}
// TODO: 2018. 03. 11. refresh lobby
out.println("Connect##Ok!");
break;
case "Disconnect":
for (ClientModel client: clients) {
if(client.getClientsocket() == clientSocket) {
clients.remove(client);
break;
// TODO: 2018. 03. 11. refresh lobby
out.println("Connect##Ok!");
break;
case "Disconnect":
for (ClientModel client : clients) {
if (client.getClientsocket() == clientSocket) {
clients.remove(client);
break;
}
}
}
out.println("Disconnect##Ok!");
// TODO: 2018. 03. 11. refresh lobby
break;
out.println("Disconnect##Ok!");
// TODO: 2018. 03. 11. refresh lobby
break;
default:
default:
out.println("Unknown Message!");
break;
break;
}
}
else
{
for (ClientModel client : clients) {
if (client.getClientsocket() == clientSocket) {
clients.remove(client);
break;
}
}
}
......
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