/// <summary> /// Create a new TCP RPC server. /// </summary> /// <param name="rpcServer">Voting RPC server.</param> public TcpRpcServer(RpcServer rpcServer) { Logger = rpcServer.Logger; this.port = rpcServer.ServerConfig.Port; this.workerCount = rpcServer.ServerConfig.WorkerCount; this.workerShortWait = rpcServer.ServerConfig.WorkerShortWait; this.workerLongWait = rpcServer.ServerConfig.WorkerLongWait; this.sqlKeepAliveTime = rpcServer.ServerConfig.SqlKeepAliveTime; this.clientTimeOut = rpcServer.ServerConfig.ClientTimeOut; this.listener = new TcpListener(new IPEndPoint(IPAddress.Any, this.port)); this.connections = new Queue<TcpRpcConnection>(); this.rpcServer = rpcServer; this.nextConnectionId = 0; }
/// <summary> /// Creates a new TCP RPC server connection. /// </summary> /// <param name="client">TCP client.</param> /// <param name="id">Connection id.</param> /// <param name="rpcServer">Voting RPC server.</param> /// <param name="clientTimeOut">Time until idle client is disconnected in seconds.</param> public TcpRpcConnection(TcpClient client, RpcServer rpcServer, ulong id, double clientTimeOut) { this.clientTimeOut = clientTimeOut; this.lastActivity = DateTime.Now; this.client = client; this.stream = this.client.GetStream(); this.writer = new BinaryWriter(this.stream); this.messageLength = 0; this.rpcServer = rpcServer; this.inBuffer = new MemoryBuffer(32768); this.outBuffer = new MemoryBuffer(32768); Id = id; if (this.client.Client.RemoteEndPoint is IPEndPoint) { IPEndPoint ipEndPoint = (IPEndPoint)this.client.Client.RemoteEndPoint; RemoteEndPointText = ipEndPoint.Address.ToString() + ":" + ipEndPoint.Port.ToString(); } else { RemoteEndPointText = "Unknown"; } }