[英]I can't disconnect my socket.io test server
I try to disconnect my client: 我尝试断开客户端连接:
public class SiecZapis {
public static Socket gniazdo2;
public static void main(String[] args) {
new SiecZapis().doIt2();
}
public void doIt2() {
try {
ServerSocket gniazdo = new ServerSocket(4242);
while(true) {
Socket gniazdo2 = gniazdo.accept();
PrintWriter pisarz = new PrintWriter(gniazdo2.getOutputStream());
String porada = "test2";
pisarz.println(porada);
pisarz.close();
System.out.println(porada);
}
} catch(Exception ex) {
ex.printStackTrace();
}
}
public void exit() {
gniazdo2.disconnect();
}
}
I tried to use something like socket.disconnect()
from this topic but there is not method disconnect
in socket
. 我尝试从本主题使用诸如
socket.disconnect()
类的东西,但是socket
没有方法disconnect
。 Could you please advise how to handle this topic? 您能否建议如何处理此主题?
Insted of disconnect try using the close method. 尝试使用close方法断开连接。
public void exit(){
gniazdo2.close();
}
Further reading: https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html#close-- 进一步阅读: https : //docs.oracle.com/javase/8/docs/api/java/net/Socket.html#close--
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.