public void Close() { if (_socket == null) { return; } _active = false; try { _socket.Shutdown(SocketShutdown.Both); } catch { } finally { _socket.Close(); _socket = null; _receiver = null; if (ClosedHandler != null) { ClosedHandler(this); } } }
public Session(string name) { _name = name ?? string.Empty; Type = SessionType.Unknown; _socket = null; _receiver = null; Active = false; _disposed = false; ConnectedHandler = null; ClosedHandler = null; ErrorHandler = null; CustomErrorHandler = null; ReceiveHandler = null; SendHandler = null; }
private void Initialize(AddressFamily addressFamily) { if (_socket != null) { Close(); _socket = null; } switch (addressFamily) { case AddressFamily.InterNetwork: Type = SessionType.IPv4; break; case AddressFamily.InterNetworkV6: Type = SessionType.IPv6; break; default: throw new Exception($"Not supported address family '{addressFamily.ToString()}'."); } _socket = new Socket(addressFamily, SocketType.Stream, ProtocolType.Tcp); _receiver = new SessionReceiver(_defaultMaxPacketLength); _receiver.Reset(_defaultPacketLength); }