user1078760
user1078760

Reputation: 749

How can I send TCP requests from my phone?

I have following task: to make Android application which connects to router, sends TCP requests for system and gets response. I have made Android application already which uses PHP web-services, but I never make application for TCP requests. Please, tell me, what means should I use for my task? Thank you.

Upvotes: 0

Views: 675

Answers (1)

Santosh
Santosh

Reputation: 17923

I guess what you are looking for is using Sockets to send raw data over the network. But its not clear what protocol you would be using. For most of the cases you will have an existing library which will save your effort on low level socket communication.

In the example mentioned here, the relevant code to look at is

         echoSocket = new Socket("remte-address", 80);
         out = new PrintWriter(echoSocket.getOutputStream(), true);

         out.println(userInput);

This is for writing to socket or sending a TCP request. On the similar lines here is the code fragment for reading response

          in = new BufferedReader(new InputStreamReader(
                                   echoSocket.getInputStream()));
           stdIn.readLine();

It will be useful if you look at the relevant socket javadoc.

Upvotes: 1

Related Questions