Beispiel #1
0
        /// <summary>
        /// Excecutes a RPC request.
        /// </summary>
        /// <param name="connection">Connection that made the request.</param>
        /// <param name="requestData">Serialized request data.</param>
        /// <returns>Serialized response data</returns>
        public override byte[] Execute(TcpRpcConnection connection, byte[] requestData)
        {
            var request = Serializable.FromBinary<RpcRequest<EchoServer>>(requestData);
              var response = request.TryExecute(connection, this);

              byte[] responseData = response.ToBinary();

              return responseData;
        }
Beispiel #2
0
        /// <summary>
        /// Excecutes a RPC request.
        /// </summary>
        /// <param name="connection">Connection that made the request.</param>
        /// <param name="requestData">Serialized request data.</param>
        /// <returns>Serialized response data</returns>
        public override byte[] Execute(TcpRpcConnection connection, byte[] requestData)
        {
            Logger.Log(LogLevel.Debug, "Connection {0}: Receiving request of {1} bytes.", connection.Id, requestData.Length);

              var request = Serializable.FromBinary<RpcRequest<VotingRpcServer>>(requestData);
              var response = request.TryExecute(connection, this);

              byte[] responseData = response.ToBinary();
              Logger.Log(LogLevel.Debug, "Connection {0}: Sending response of {1} bytes.", connection.Id, responseData.Length);

              return responseData;
        }
Beispiel #3
0
        /// <summary>
        /// Listens for connection.
        /// </summary>
        private void Listen()
        {
            this.listener.Start();

              while (this.run)
              {
            while (this.listener.Pending())
            {
              try
              {
            TcpClient client = this.listener.AcceptTcpClient();
            ulong connectionId = 0;

            lock (this.connections)
            {
              connectionId = this.nextConnectionId;
              this.nextConnectionId++;
            }

            TcpRpcConnection connection = new TcpRpcConnection(client, rpcServer, connectionId, this.clientTimeOut);

            lock (this.connections)
            {
              this.connections.Enqueue(connection);
            }

            Logger.Log(LogLevel.Info, "New connection {0} from {1}.", connection.Id, client.Client.RemoteEndPoint);
              }
              catch (SocketException socketException)
              {
            Logger.Log(LogLevel.Warning, "New connection failed: {0}", socketException.Message);
            this.listener = new TcpListener(new IPEndPoint(IPAddress.Any, this.port));
            this.listener.Start();
              }

              Thread.Sleep(1);
            }

            Thread.Sleep(10);
              }

              this.listener.Stop();
        }
Beispiel #4
0
 /// <summary>
 /// Excecutes a RPC request.
 /// </summary>
 /// <param name="connection">Connection that made the request.</param>
 /// <param name="requestData">Serialized request data.</param>
 /// <returns>Serialized response data</returns>
 public abstract byte[] Execute(TcpRpcConnection connection, byte[] requestData);