I have a server that runs on Amazon ec2, which listens to a socket and prints the message ("hello world") sent by the client - which is an activity (android app).

I'm trying to send messages from the activity to the server in a function, for example: after a button is clicked to send the server a message that a button was clicked. I created a connectionHandler class which extends a thread and handle the connection to the server and writes the "hello world" message. I want to create a function called "send" that receive a string, that an activity can call it and the message will be passed to the server.

My connectionHandler is a thread, so when I start it, it just execute the run() function, and once it finished I cannot call other functions to send messages.

I hope I was clear with my question, Thanks, Itai.

有帮助吗?

解决方案

Making a connection to server from android device with a thread call is a very wrong approach. You should use Asynctask or a library called volley which can make your work easier .

Reference link using Asynctask: http://developer.android.com/training/basics/network-ops/connecting.html

Reference link using Volley: http://www.michenux.net/android-volley-and-gson-tutorial-797.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top