[英]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? 它是否使用
write
将消息发送到端口8090,是否还需要添加flush?
try {
InetAddress addr = InetAddress.getByName("127.0.0.1");
int port = 8090;
Socket socket = new Socket(addr, port);
} catch (UnknownHostException e) {
} catch (IOException e) {
}
查看“ 自定义网络”教程中的一些可用示例。
You can get the output stream object from the method socket.getOutputStream(). 您可以从方法socket.getOutputStream()获取输出流对象。 Once you get the output stream you can write using the stream.
一旦获得输出流,就可以使用该流进行写入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.