cannot connect to remote server via socket

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

cannot connect to remote server via socket

Postby bruce » Thu Nov 05, 2009 9:53 am

Hi Guys
My application use socket to connect a remote sever to get data.
In my handset, both Wi-Fi and Mobile network data connection are enabled, by default device will choose using Wi-Fi connection. In this case, all network access can process normally
However, when I turn off Wi-Fi in system setting page and switch back to my application to start a new session for network access(it will use mobile network), I found that socket could not setup( constructor Socket(String hostname, int port) method does not return).
But if I kill the process then restart application, my application can communicate with server via mobile network normally
Any one know what's the reason for this?

In my application, each time I send a request to server, a new Socket object will be created.
public class SocketConnection implements IConnection{

private Socket sock;

/**
* Initialize the socket
*/
public SocketConnection(IConnectionConfig config) throws IOException, SecurityException{
sock = new Socket(config.getHostName(), config.getHostPort());
}

/**
* @see Connection#openInputStream()
*/
public InputStream openInputStream(){

try {
return sock.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

/**
* @see Connection#openOutputStream()
*/
public OutputStream openOutputStream(){
try {
return sock.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

/**
* @see Connection#close()
*/
public void close(){
try {
sock.close();
} catch (IOException e) {
e.printStackTrace();
}

}

}

Many thanks
bruce
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Nov 05, 2009 9:42 am

Top

Postby sunkillen » Fri Nov 06, 2009 6:01 am

Good question! Anybody knows? :D
sunkillen
Freshman
Freshman
 
Posts: 3
Joined: Tue Jun 24, 2008 8:58 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 7 guests