1

Hay Guys, I'm new to Android but heres what i want to do.

I want to beable to open a connect to a server using a given IP and PORT, then send commands to the server and get data back.

Any ideas what i need to google to help on this? I know how to do it in PHP (using fputs, fgets, and fsockopen).

any help would be brill.

Thanks

1 Answer 1

3

Use the java.net classes. Below is a simple example using DatagramSockets:

String cmd("my command");
    try {
        InetSocketAddress address = new InetSocketAddress("10.1.1.1", 12350);
        DatagramPacket request = new DatagramPacket(cmd.getBytes(), cmd.length(), address);
        DatagramSocket socket = new DatagramSocket();
        socket.send(request);
    } catch (SocketException e) {

        ...
        }
    } catch (IOException e) {

       ...
        }
    }

Other Java samples can be found here:

1
  • I've managed to connect to a server using Socket(), but i cant send any commands. Any ideas?
    – dotty
    Jan 26, 2010 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.