Example #1
0
        /// <summary>
        /// Initializes a new instance of the ClientConnection class.
        /// </summary>
        /// <param name="connected">The socket for the new connection.</param>
        /// <param name="matchmaker">The matchmaker service to use.</param>
        public ClientConnection(Socket connected, Matchmaker matchmaker)
        {
            // -
            // Set up the connection state.
            // -
            this.socket = connected;
            this.matchmaker = matchmaker;

            // -
            // Prepare our buffer space and asynchronous state holder.
            // This is currently just a simplistic single buffer system.
            // Note that this code assumes that the buffer is larger than
            // the largest possible HTTP Request-Line we want to handle.
            // -
            this.buffer = new byte[1500];
            this.bufferOffset = 0;
            this.eventArgs = new SocketAsyncEventArgs();
            this.eventArgs.UserToken = this;
            this.eventArgs.Completed +=
                new EventHandler<SocketAsyncEventArgs>(this.IOCompleted);
            this.eventArgs.SetBuffer(this.buffer, 0, this.buffer.Length);

            // -
            // Look for incoming data from the client.
            // -
            this.StartReceive(0, this.buffer.Length);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the CloudService class.
 /// </summary>
 public CloudService()
 {
     this.startTime = DateTime.UtcNow;
     this.keymaster = new Keymaster();
     this.matchmaker = new Matchmaker();
     this.serviceListener = new ConnectionListener(
         Settings.ServicePort,
         this.ServiceConnectionAccepted);
     this.clientListener = new ConnectionListener(
         Settings.ClientPort,
         this.ClientConnectionAccepted);
 }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the ServiceConnection class.
        /// </summary>
        /// <param name="connected">The socket for the new connection.</param>
        /// <param name="keymaster">The authentication authority to use.</param>
        /// <param name="matchmaker">The matchmaker service to use.</param>
        public ServiceConnection(
            Socket connected,
            Keymaster keymaster,
            Matchmaker matchmaker)
        {
            // -
            // Set up the connection state.
            // -
            this.socket = connected;
            this.keymaster = keymaster;
            this.matchmaker = matchmaker;
            this.state = ConnectionState.PeerNotVerified;

            #if true
            // -
            // We use keep-alives on the home <-> cloud service
            // connection in an attempt to prevent NAT/firewall
            // state from timing out and dropping our connection.
            // -
            StaticUtilities.SetKeepAlive(this.socket, 50000, 1000);
            #endif

            // -
            // Prepare our buffer space and asynchronous state holder.
            // This is currently just a simplistic single buffer system.
            // Note that this code assumes that the buffer is larger than
            // the largest possible single message (currently 257 bytes).
            // -
            this.buffer = new byte[1500];
            this.bufferOffset = 0;
            this.eventArgs = new SocketAsyncEventArgs();
            this.eventArgs.Completed +=
                new EventHandler<SocketAsyncEventArgs>(this.IOCompleted);
            this.eventArgs.SetBuffer(this.buffer, 0, this.buffer.Length);
            this.eventArgs.UserToken = this;  // Keep GC from collecting us.

            // -
            // Start the dialog with our peer.
            // -
            this.AppendMessage(
                MessageType.Version,
                ServiceConnection.ProtocolVersion);
            this.AppendMessage(MessageType.PleaseIdentify);
            //this.SendMessage();
        }