我有网络应用程序和应用程序具有静态IP和端口的热敏打印机
通过服务
我的代码C#:
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);
//ReuseAddress : Allows the socket to be bound to an address that is already in use.
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
socket.Connect(remoteEP);
socket.SendTimeout = 2000;
socket.ReceiveTimeout = 2000;
socket.Send(data, data.Length, SocketFlags.None);
socket.Receive(data);
//The shutdown function Disables sends and receives on a Socket.
socket.Shutdown(SocketShutdown.Both);
//Closes the socket connection and allows reuse of the socket.
socket.Disconnect(true);
//Closes the Socket connection and releases all associated resources.
socket.Close();
但有些时间套接字没有关闭,我无法创建带打印机的新套接字
那么我如何检查套接字是否关闭以及如何在创建新套接字之前打开它的接近程度????
请帮助我!!