79 comments:

Hi! Nice article.Ive been trying some different ways to get a page using Get and Post methods.Ive tryed classic sockets, java.net.URLConnection and http components from org.apache.http...Ive found that Apache Http Components and classic Sockets are very laggy and sometimes timeout when trying to connect to the remote web.And URLConnection from java.net performs better for this task, but not outstanding.After debugging a while i saw using Wireshark that almost 40% of packets sent are retransmissions and the 3way handshake of tcp doesn't or cant answer to SYN+ACK packets, only to SYN ones.Have you heard about a bug or experienced something like this?Have you a 1 or 2 sec lag in the connection stablishment in your tutorials?Thanks!

ya iv too tried it iv got it thank you very much now i am trying it on an Android Device so now i am trying to modify the code so that i can use it for something like home automation purpose like phone to PC PC to a switching module and thank you once again

hi i am working on TCP communications using toggle buttons like i am using 2 buttons on click of one a message should go to the server so i have written a code but i am getting errors so shall i forward you the code can you help me in it?

Yes I have placed it. What I am trying is to run the local server (that you wrote in the next exercise) and this application on the same pc. I tried all possible combinations, (localhost, my ip address, etc..) (I am using eclipse classic 3.6.2, and my avd 5554). It is telling me fatal exception. Sorry I am totally new to android :sThank you again.

Thanks a lot! This article helped me a lot! I have got a simple newbie question though, if i for example send g-sensor data to this textOut editText, how can i loop this client, to send this data to pc in real time? Please help :) Thanks again!

hi sir, i'm a newbie in android Programming. what would be the cause if my emulator pops up a message "the Application testandroid(process com.test) has stopped unexpectedly. Please try again" i followed all the step you indicated in your post. tnx in advance...

Thank you so much this was really helpful! Please I want to know how i can let the android emulator acting as a server send a message back to the client. Does port forwarding also have to do with this? i really appreciate ur help because i need both to exchange msgs via tcp

hi all,can any one send me code for establishing a socket connection between two emulator.. or private channel between two emulator...please if not code also sugest me how to do.. its urgent..reply u mail to thismanju.shirageri@gmail.com

Thanks for the tutorial. I am new to the android programming. I tried the source code and it works on the emulator and local PC, but when i deploy the apk into my android. It stuck at the screen and no response.. Anyone can help? Thanks

First of all, very nice blog about android development you made! I'm starting now and found many interesting things here...

I tried to build this tcp client but android always crashes on the new socket line.

I changed it to my desktop's IP, checked if I can ping it from my Android phone and I can. I also can ping the phone from the desktop. I added the uses permission on manifest.

It crashes both on phone and the emulator.

If you have any idea I would be very grateful. I tried many socket codes from internet but they all crash when creating the new socket, so I think it's something very basic I missed, but no idea of what could be...

hello,i'm a newbie in android, I'm under linux 12.04, eclipse and i try to communicate with my Android 2.2 phone using your application , but i get this error message in the eclipse console:java.net.socket exception: Network unreachable

hi, i have been trying to implement the same program and it does not work. the graphical interface works ok, but when i send the data the program stops working and the emulator goes to the main page in the android emulator. in order to make it run i had to make two changes:1. change "AndroidClient" to "AndroidClientActivity" in public class AndroidClient extends Activity2. i have to delete the "@Override" that is just over "public void onClick(View arg0) {"

i have installed android sdk and eclipse according to http://developer.android.com/sdk/installing.html. finally, i am using the sdk=15 (which i have also changed in the manifest file).

Thank you for the code.But I have a doubt.I have written the client in 2.2 and made a java project for the server. When I run the client on the emulator and the server code it works well. But I want to run the client on my phone. The client opened in my phone, but when I try to send the data, it doesnt go ahead. I connected my phone and laptop with WiFi. And in the laptop's web browser I wrote the IP of my laptop : <8888>Am I doing this correctly? Please assist if I m wrong. And kindly tell why am I not able to send the data. My phone has version 2.3.6

Hi,I tried to run this application but when i click the send button on my emulator it just crashes and i get an error on the second @override below this line of codeButton.OnClickListener buttonSendOnClickListener = new Button.OnClickListener(){i would appriciate the help i have a project to do before my school starts thnx...

@Monisha M: If you don't mind I would like to try to answer your question. have you added the EditText named textOut in the xml? check it in R.java if its declared in the id part.. cz your error suggests something like this..

Hi,It is working fine for me when I followed the procedure that you mentioned in your article.

But When I try the reverse process where I created a ServerSocket in android and a socket in Java, the ServerSockets reads the data only once. After that I see the exception in Java console as "java.net.SocketException: Connection reset by peer: socket write error"Could you please tell what the problem could be ??

Hello there , thanks for this post , but i have a problem , how can I make 2 android devices talk with each other via texting , not from pc-android , I want android-android example , I hope you could help me with this issue

Hi, I have a question. What IP should I use if I want to run this application from a real android phone, and not from the emulator. My computer is directly connected to internet, it's not connected through a wifi router. My phone is connecting through an wifi connection shared by my computer (I'm using connectify software to do this). So what IP should I use to make it work. I've tried some of them, but the application doesen't do anything, it eneters in a non responding state. Please help me with this, I've seen that you tried this and worked for you.

I would like to ask your help.I tryed your client code and after connecting it did not get datas.What is the problem. It it is possible can you give me the good codes. My mail address is schubertjw@gmail.com.Than you....

hi thanks for the tutorial. now i understand about the socket and the server concept in java.

I want to develop an app that will be deployed in two android devices for making them communicate through wifi. And here is the case:

Two devices are turning on their Wifi They're not connected to any network. No LAN, no bluetooth, no phonecall, no internet They want to discover each other devices They want to communicate each other (sending simple string). They don't want the intermediary devices for direct communication. They are not having Wifi Direct capabilities.

is it possible? How to do that?

I read socket and server concept in java, but they need to be connected each other / to any networks. Which means it is not what in my case (above). I need to know how each device could discover each other first before connecting them. And how to do that in Wifi?

I found Chord SDK. that simplify the wifi coding in android. But that only available for Samsung device. Sigh.

I found JXTA for peer2peer communication on java. But it need RDV to list down the IP address for the peer to acknowledge each other. Which means not fit to my case (above).

I found alljoyn library. But the examples are too complex to follow.

I found NearBytes SDK. it simple code that makes the devices communicate each other. I like it. But it only available for shorter distance (few centimeters). Which is not fit to my case (above).

Hi,am creating android barcode reader over wifi to pc .. i can send the barcode data to pc with the help of this socket programming .... BUT it only print in the eclipse teminal ...I want to print it in the text field in php file....

Hi, it is really nice tutorial, the problem is that i tried to run server it was ok.. it is working fine but when i try to pass the value from android emulator it is giving me error networkOnMainThread exception and application crashes.i also tried it inside thread to avoid networkonmainthread. the program do not crashes but server do no get any response...

hi, i just try your code.and i can connect to socket and send string with emulator.but, when i run this code in real device i cant connect or send string to socket.the application force quit and my device is hang.pliss help my problem...,what's wrong with this code or my real device.FYI i try this code in emulator with JelyBean 2.1 and succses.but i try this code in Real Device with JellyBean 2.1 to, i can run the aplication, but when i try to connect or send string the aplication is not responding, and the device is hang.

For those of you wondering about getting the client work on your phone and the server to work on your computer, here's a possible solution if your server machine is on a wifi network. What I ended up doing was enabling port forwarding on my wireless router. As Android-Er said, this is different for every router, so you'll have to figure out how it's done on yours. But basically in your router's port forwarding settings you enter the ip address of your server computer and the port the server is listening on, and then enable port forwarding for that ip address and port. And naturally, the same principle applies to a wired router, too. But you'll need to figure out how to get into the admin settings on your router, and then where the port forwarding feature is within those settings.