How to get data to/from a socket in a thread?

Android noob here. I learn the best by seeing the source code of a functional example, but I have been unable to find a simple-but-complete example of using a socket in its own thread.

I have an Android service that needs to communicate with the Internet. I want to open a TCP socket that connects to a server on the Internet. The service needs to send data to the Internet, and data coming back from the net will need to go to the service. Since the service is doing other things as well, the socket connection needs to live in its own thread.

Any idea where I could find an example of a socket in a thread with communication to/from the socket?

Thanks

enter image description here

9
задан Alex Coplan 29 December 2011 в 17:48
поделиться