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; }
public void Close() { if (_socket == null) { return; } Active = false; try { _socket.Shutdown(SocketShutdown.Both); } catch { } finally { _socket.Close(); _socket = null; _receiver = null; ClosedHandler?.Invoke(this); } }
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); }