How to send message to socket client
I would like to add a method to send a String of message to client, it was hard to find a good example on the web. Does it use write
for sending message to port 8090, do I need to add flush as well?
try {
InetAddress addr = InetAddress.getByName(开发者_高级运维"127.0.0.1");
int port = 8090;
Socket socket = new Socket(addr, port);
} catch (UnknownHostException e) {
} catch (IOException e) {
}
Check out the Custom Networking tutorial for some working examples.
You can get the output stream object from the method socket.getOutputStream(). Once you get the output stream you can write using the stream.
精彩评论