my dog learned polymorphism*
The moose likes Android and the fly likes TCP socket ip address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "TCP socket ip address " Watch "TCP socket ip address " New topic
Author

TCP socket ip address

Akil Kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 83
Hello,

I have the client socket written in Android and the server is written in C. I am running the C server from my machine using cygwin. The client is running on the emulator in the same machine. Now I am using java.net.Socket in the client to establish the TCP connection. In the socket I have mentioned my machine's ip address and the server is listening to port 10001 so I have mentioned the port number as 10001.

I retrieved my machine's ip by the following steps. In the command prompt I entered ipconfig and what ever ip listed there, I mentioned the same address in the client socket.

I also modified the manifest file and set the internet permission.

So now when I start the server using cygwin and then run the android application from Eclipse.

My application is not loading and it gives me an error "The application has stopped unexpectedly".
Sometimes if I change the target AVD in the run configuration to 1.6 instead of 2.0 it gives me the error "launch error sad result from adb".

All I need to do is establish a tcp/ip connection between the client and server and read some data from the server.

Can anyone please help me on this? I am stuck with this issue for long time.

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Whenever an application crashes there's generally some output (at least a stack trace) in the logcat logs that help in pinpointing the problem.


Ping & DNS - my free Android networking tools app
Akil Kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 83
I checked the log cat console. There was a null pointer exception from the thread which I started. I handled that and ran the application again. Still it is giving me the same error. I am wondering if I am doing anything wrong in specifying the ip address or port number in the android client. Can anyone ensure whether it (what I mentioned in my initial post about ip) is correct or not?

Because the same program if I run it as a standalone Java application it reads the data from the server without any issues.

Is the android emulator's ip address is the same as my machine's ip address?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
There was a null pointer exception from the thread which I started. I handled that and ran the application again. Still it is giving me the same error.

What do you mean by "handled"? If you handle an NPE then it can't happen because you'd be checking the object for being null before calling a method on it.
Akil Kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 83
Yes I did the same thing. In my case I am reading data from the DataInputStream in a background thread. So I am checking if in.available() > 0 inside run() method.
After doing this, I reran the application. It gives the same error but when I check logcat it doesn't show anything.

Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: TCP socket ip address