/// <summary> /// Called by socket Close functiion /// </summary> /// <param name="closingChannel"></param> internal void SocketClosingConnection(InProcSocket closingChannel) { Network.ConnectingSockets.Remove(SocketId.FromSocket(closingChannel)); if (closingChannel.State == ConnectionState.Closed) { throw new Exception("Only connected socket can be closed"); } else if (closingChannel.State != ConnectionState.Established) { closingChannel.ChangeStateTo(ConnectionState.Closed); } else { closingChannel.ChangeStateTo(ConnectionState.Closing); if (closingChannel.ParentServer != null) { closingChannel.ParentServer.RemoveClientChannel(closingChannel); } Network.EstablishedSockets.Remove(SocketId.FromSocket(closingChannel)); Network.TaskScheduler.SchedluleTask(() => { // find socket associated with closing one InProcSocket remoteChannel = null; if (!Network.EstablishedSockets.TryGetValue(SocketId.RemoteSocketId(closingChannel), out remoteChannel)) { return; } closingChannel.ChangeStateTo(ConnectionState.Closed); remoteChannel.ChangeStateTo(ConnectionState.Closed); // if remote socket belongs to server if (remoteChannel.ParentServer != null) { remoteChannel.ParentServer.RemoveClientChannel(remoteChannel); } Network.EstablishedSockets.Remove(SocketId.FromSocket(remoteChannel)); }, TimeSpan.FromMilliseconds(Network.ConnectionCloseLatency)); } }
internal bool SocketSendMessage(InProcSocket socket, object message) { if (socket.State != ConnectionState.Established) { throw new Exception("Only connected sockets can send messages"); } InProcSocket destinationSocket = null; if (!Network.EstablishedSockets.TryGetValue(SocketId.RemoteSocketId(socket), out destinationSocket)) { throw new Exception("Failed to send message, destination socket not found"); } Network.TaskScheduler.SchedluleTask(() => { destinationSocket.RaiseMessageReceived(message); }, TimeSpan.FromMilliseconds(Network.GetConnectionDelay(socket, destinationSocket))); return(true); }