开发者

android open socket and send commands

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

I want to beable to open开发者_Python百科 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


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:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜