private void DoNewConnection(IAsyncResult state) { if (!IsDisposed) { TcpListener listener = (TcpListener)state.AsyncState; if (listener.Server.IsBound) { try { Socket clientSocket = listener.EndAcceptSocket(state); if (IsTcpConnectionAlive()) { clientSocket.Close(); } else { HealthCheckedTcpSocket socket = new HealthCheckedTcpSocket(clientSocket, RdmSourceId, SenderId, SourceName); socket.UnhandledException += socket_UnhandledException; socket.Open(new IPEndPoint(IPAddress.Any, 0)); AliveTcpSocket = socket; } } finally { listener.BeginAcceptSocket(new AsyncCallback(DoNewConnection), listener); } } } }
public static HealthCheckedTcpSocket Connect(RdmEndPoint endpoint, Guid senderId) { Socket newConnection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); newConnection.Connect(endpoint); HealthCheckedTcpSocket socket = new HealthCheckedTcpSocket(newConnection, endpoint.Id, senderId, string.Empty); socket.Open(endpoint); return(socket); }