• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Socket communication

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks

 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Akil Kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now I am running on the same machine. I start the server using cygwin and run the client from eclipse.
I came across few sample android socket code where they had created 2 threads like

Thread thread1 = new Thread(new TCPClient());
Thread thread2 = new Thread(new TCPServer());

In my case since the server code is written in C, I was wondering how this is possible.

Thanks
 
Akil Kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Thanks
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Akil Kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


Thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic