简体   繁体   中英

Connecting to tcp server from client running in android device

I am trying to connect to a standalone desktop tcp server(java) from tcp client application in android device.

But I am not able to connect to that.

I tried to write a desktop tcp client and tried to connect to server(remote server). It is working fine.

But When I am trying to connecting from android, I am getting a IOException while creating Socket instance.

Can anyone help me in this ? Thanks in advance....

I am answering my own question :)

Now, I am able to connect to server running in my PC from client running in Android device.

The problem is,

My server running in PC is connected to different IP N/W than the Wi-Fi N/W used by my Mobile. So even if I give the same IP address in client to connect to server, it can not connect, because IP address is relative(local) to the IP N/W.

So, if we are using relative IP for Server, we need to make sure that the both Server and client running devices should be connected over the same IP N/W.

It is a silly question and silly mistake and silly answer. :)

OK... for the time being we are doing this by checking the connection every n seconds.

Timer.scheduleAtFixedRate( new TimerTask() {
public void run() {
.....
}
}

But, still I want to know if there any way like getting callback upon socket connection lost...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM