java - TCP sender android -
please tell me simple example of sending message protocol tcp android. how implement method of sand (ipserver,port);
string host = ...; // host name can either machine name, such "java.sun.com", or textual representation of ip address int port = ...; socket socket = new socket(inetaddress.getbyname(host), port); bufferedreader reader = new bufferedreader(new inputstreamreader(socket.getinputstream())); printwriter writer = new printwriter(socket.getoutputstream(), true); // true auto flush now, can send message through writer, like:
writer.println("hello world"); and can read incoming data through reader, like:
string incoming = reader.readline();
Comments
Post a Comment