Всякий раз, когда я звоню SocketServer
, приложение принудительно закрывает приложение. Если я запускаю его в фоновом режиме, он пропускает этот код.
public void run() {
try {
//Log.e("Debugging Data: ", "-------------->>>>> Here "+LocalServerThread.getState());
if (LocalServerThread.getState() == Thread.State.RUNNABLE) {
try {
if(socClient!=null) {
ServerAsyncTask serverAsyncTask = new ServerAsyncTask();
serverAsyncTask.execute(new Socket[]{socClient});
}
}
catch(Exception ex)
{
Log.e("Debugging Data: ", "-------------->>>>> Server ERROR "+ex.getMessage());
}
}
}
catch(Exception ex)
{
Log.e("Debugging Data: ", "Not Running");
Log.e("Debugging Data: ", "New Thread Created");
LocalServerThread = new Thread() {
@Override
public void run() {
try {
//ServerSocket socServer = new ServerSocket(8088);
while (true)
{
socServer=null;
socServer = new ServerSocket(5000);
Log.e("Debugging Data: ", "-------------->>>>> 1 ");
socClient = socServer.accept();
Log.e("Debugging Data: ", "-------------->>>>> 2 ");
//Log.e("Debugging Data: ", "New Thread Running");
if(socClient==null) {
Log.e("Debugging Data: ", "SOC Client nULL");
socClient = socServer.accept();
Log.e("Debugging Data: ", "New SOC Client Created");
}
ServerAsyncTask serverAsyncTask = new ServerAsyncTask();
serverAsyncTask.execute(new Socket[]{socClient});
}
} catch (IOException e) {
Log.e("Debugging Data: ", "New Thread Error "+e.getMessage());
e.printStackTrace();
}
}
};
LocalServerThread.start();
Log.e("Debugging Data: ", "-------------->>>>> Here2 "+LocalServerThread.getState());
}
}