简体   繁体   中英

ServerSocket open and immediate close on localhost will lead to TIME_WAIT?

I am seeing following logic in one of the java libs to test open of socket on localhost:

 ServerSocket socket = new ServerSocket(port);
 socket.close();

My question is would this socket lead to TIME_WAIT state on localhost when no data packets have been sent and socket is closed immediately after opening it? In such a case if the application attempts to bind to same port can it cause 'address already in use error' if done within 2MSL value?

I wrote a small test program like above, but when I netstat or ss on linux machine where I ran this program, I do not see TIME_WAIT at all for this port. Shouldn't the state machine apply even in case the socket has not been used to send any data packets?

TIME_WAIT is a state in a connection. You haven't created a connection, ergo you never reach TIME_WAIT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM