Friday, June 25, 2010

Re: [android-developers] ServerSocket problem


do you know what's the ip address you got on the real device.

There are chances the real device is on NAT network. In such a case you wont be able to talk directly to the device.


On Fri, Jun 25, 2010 at 12:04 PM, Alex Xin <xinxiaoc@gmail.com> wrote:
more on this problem...

it works great in emulator, but always failed on real device


On Sat, Jun 26, 2010 at 1:03 AM, Alex Xin <xinxiaoc@gmail.com> wrote:
Hi, folks

I'm now facing a very strange server socket problem, I have a server that will listen on a TCP port, I use the following code to do this work.

public class RequestListenerThread extends Thread {

private final ServerSocket serversocket;

public RequestListenerThread(int port, final String docroot)
throws IOException {
this.serversocket = new ServerSocket(port);
setDaemon(true);
}

public void run() {
Log.v("FE", "SMB Server Listening on port "
+ this.serversocket.getLocalPort());

while (!Thread.interrupted()) {
try {
// Setup incoming client connection
Socket socket = this.serversocket.accept();
Log.v("FE", "Incoming connection from "
+ socket.getInetAddress());
// Start worker thread
Thread t = new WorkerThread(socket);
t.start();
} catch (InterruptedIOException ex) {
break;
} catch (IOException e) {
Log.v("FE", "Network I/O error: "
+ e.getMessage());
break;
}
}
}
    }

My target device is running on Android 1.6.

When I run this code, it can start to listen on port but can't accept any incoming connections. When it runs into serversocket.accept function, it never return, just like dead lock. 

Does anybody has the same issue? How do you solve this problem?

Thanks very much

Alex

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment