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 void AddKnownDevice(RdmEndPoint endpoint) { if (!devices.ContainsKey(endpoint)) { HealthCheckedTcpSocket device = HealthCheckedTcpSocket.Connect(endpoint, SenderId); device.UnhandledException += device_UnhandledException; device.NewRdmPacket += device_NewRdmPacket; devices.Add(endpoint, device); } }
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); }
public HeartbeatProtocolFilter(HealthCheckedTcpSocket parent) { this.parent = parent; }