NOTE: It is normal to have a socket in the TIME_WAIT state for a long period of time. The time is specified in RFC793 as twice the Maximum Segment Lifetime (MSL). MSL is specified to be 2 minutes. So, a socket could be in a TIME_WAIT state for as long as 4 minutes. Some systems implement different values (less than 2 minutes) for the MSL.
所以显示Time_Wait是正常的。
nSocketPort A particular port to be used with the socket, or 0 if you want MFC to select a port.
将第一个参数设为0即可,
不然你就判断Create 是否成功,如果失败,则换一个端口。
Unix 和Windows 都支持这种方法。
下面是socket()的说明:
If an application does not care what local address is assigned, specify the manifest constant value ADDR_ANY for the sa_data member of the name parameter. This allows the underlying service provider to use any appropriate network address, potentially simplifying application programming in the presence of multihomed hosts (that is, hosts that have more than one network interface and address).