I am trying to establish a TCP connection between android client and C sever. My android device will be the client. Is this possible in android?
If so can I use separate threads for client and server. How will I be able to call the server thread from android?
Can anyone provide some help?
Lester Burnham wrote:Yes, you can use the java.net.Socket class, like you would on any other Java platform. Your application will need the android.permission.INTERNET permission.
Not sure what you mean by "separate threads for client and server", though. Obviously they will run in separate threads - they are in fact running on different machines, no?
In order not to block the GUI, you may be better off to run the Android client in an AsyncTask that updates the GUI as appropriate.
But I have written the client socket in Java to read the data from server. I need to plot a graph in the view with the data and test in emulator.
So I was wondering how should I incorporate the above written code in the view and plot the graph.
I came across few sample android socket code where they had created 2 threads like
I don't know what those apps did, but in your case the server isn't even in Java, much less running on the same machine as the client, so there'll be no thread in the JVM for it.
But I have written the client socket in Java to read the data from server.
What do you mean, "but"? If you already have the client code, then all is well from the networking perspective, no?
I need to plot a graph in the view with the data and test in emulator. So I was wondering how should I incorporate the above written code in the view and plot the graph.
Plotting data is a wholly different issue than client/server communication, and you should start a new topic about this. Let this topic be about how you can receive all data you need from the server. Once you have that working, start worrying about how to display it. If you mix both you'll just end up confusing yourself.
Currently for the testing purpose I run the client and server on the same machine. But when it comes to the real time application my android handheld device will be client and the server will be physically present some where.
The server code is written in a different language because of memory constraints and no room for JVM.
I have already finished reading the data from the server based on the network byte order and its reading the data properly.
Yes from the networking standpoint its done.
That's why I have started thinking about the display part. Now I need to check with those data how the display looks like.
This part of program which I wrote was a standalone Java program and now I need to create a view and activity for this.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop