NXT-Spy – First successful parallel Wi-Fi data transfer between the phone and the PC

Yes, after several hours trying to get it work, I managed to do a “full duplex” data transfer between my HTC Hero and my PC through a router.

First, I read some examples here on how the data transfer over a network were working in JCSP and tried to implement it. So I wrote a simple Android app for the phone and a simple Java app for the computer, I ran it and as usual, it did not work.

I finally figured out that I first had to initiate a server connection on each devices before I could do any client connection thanks to Kevin Chalmer’s examples [source], so I did a little UI for the phone with two buttons : “Start server” and “Connect”. Everything looked nice and should have perfectly worked well but I fell on a very strange situation : the messages from the phone arrived perfectly on the PC but the PC just could not send any messages to the phone.

I first thought that I did a mistake about the ports I was using so I changed them several times with no result. I scanned the requests with Wireshark that just confirmed the fact that the requests from the PC were not reaching the phone.

I then thought that I needed to add some permissions to tell the phone to keep its server port opened but there were no such things.

I finally, desperatly went into the org.jcsp.net sources to reverse engineer the server socket creation hoping to see where the problem was by using log report messages. As predicted, in the socket’s run method, the thread was stuck waiting for a client to come.

So the phone was waiting for a client but the computer was trying to connect, a really unusual situation. So I kept on searching for a solution until I did a modification that solved my problem : I just removed the InetAddress parameter from the ServerSocket because it was not necessary and it worked.

But I didn’t want to just modify this class and leave it like that, I wanted to find a real solution to my problem that looked like a server IP address problem. So after a little bit more studdies of the I finally found where the problem was coming from in the TCPIPLinkServer class :

In fact, when we don’t supply any IP address for the server connection, the TCPIPLinkServer class calls this piece of code to get the IP of the network card the will be used by the server :
InetAddress toUse = InetAddress.getLocalHost();
Instead of that, on Android, it returns 127.0.0.1 !

So the solution to my problem was simply to provide the phone’s IP address as a parameter of the server initialization. And it worked!

So I now have all the elements to code the camera images transfer over Wi-Fi and I will probably do it soon ;).

Supervisor’s comment:

For the meeting on 12th October please will you write up how you built JCSPae to include the connection to the Android widgets

Leave a Reply

Your email address will not be published. Required fields are marked *