[英]Problems in java TCP socket close and reopen
i am writing an application in java swing which uses socket to connect to python agent, send and receives data over the socket and closes, 我正在用java swing编写一个应用程序,该应用程序使用套接字连接到python代理,通过套接字发送和接收数据并关闭,
now when i try to reopen the socket, it gives me error, 现在,当我尝试重新打开套接字时,它给了我错误,
i tried checking socket status after socket is closed, i stuck on following problem 我尝试在关闭套接字后检查套接字状态,但遇到以下问题
clientSocket //is my java socket,
clientSocket.isConnected() //returns true
clientSocket.isBound() //returs true
clientSocket.isClosed() //return true
can anybody help, how can i ensure what is status of my socket? 谁能帮忙,我如何确保插座的状态是什么?
Do not try to reopen a closed socket. 不要尝试重新打开封闭的插座。 Instead, reinitialize it calling the same constructor.
而是,重新初始化它,调用相同的构造函数。
Create a new socket each time. 每次创建一个新的套接字。 When you close the socket the file descriptor is released and the socket is no longer available.It cannot be reopened.
关闭套接字时,文件描述符将被释放并且套接字不再可用,无法重新打开它。 From the jdk:
从jdk:
Once a socket has been closed, it is not available for further networking use (ie can't be reconnected or rebound).
插座一旦关闭,便无法再用于网络连接(即无法重新连接或反弹)。 A new socket needs to be created.
需要创建一个新的套接字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.