I am starting two asynchronous task in two diffrent services first one works correctly and opens a socket but second one is not starting here is the code my application is based on client socket programing in wifip2p.
public class RecieveAudioService extends Service {
String tag = "Recieve Audio Service";
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(getApplicationContext(), "Recieve audio :requesting to client", Toast.LENGTH_LONG).show();
String[] param = {"h", "j", "k"};
new request().execute();
Log.v("Recieve Audio", "Inside Recieve audio service");
return super.onStartCommand(intent, flags, startId);
}
//===================== This class is sending request to server for connection when invocked
public class request extends AsyncTask<String, String, String> {
protected String doInBackground(String... arg0) {
Log.v("second asyn", "this is second asynchronous task");
try {
Toast.makeText(getApplicationContext(), "Request to connect sent to server",
Toast.LENGTH_LONG).show();
String toConnectDeviceIP = "192.168.49.1";
Integer toConnectDevicePort = 8988;
Socket connect = new Socket();
connect.bind(null);
connect.connect((new InetSocketAddress(toConnectDeviceIP, toConnectDevicePort)),
5000);
Log.v(tag, "sent the connection request to clint");
connect.close();
} catch (Exception e) {
// TODO Auto-generated catch block
Log.v(tag, "" + e.toString());
Toast.makeText(getApplicationContext(), "i found exception in connection"
+e.toString(), Toast.LENGTH_LONG).show();
}
return "success";
}
}
//====================================================================
}