Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="SimpleClientTcpSocket"/>.
        /// </summary>
        public SimpleClientTcpSocket()
        {
            // Create the underlying socket and hook up its Connect event.
            Socket = new ClientTcpSocket();
            Socket.ConnectCompleted += SocketConnectCompleted;

            // Create the receive buffer for the socket.
            Packetizer = new SocketPacketProtocol(Socket);

            // Initialize the keepalive timer and its default value.
            KeepaliveTimer          = new Timer();
            KeepaliveTimer.Elapsed += KeepaliveTimerTimeout;
            KeepaliveTimer.Interval = TimeSpan.FromSeconds(5);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of <see cref="SimpleServerChildTcpSocket"/>.
        /// </summary>
        /// <param name="socket">The socket to wrap.</param>
        internal SimpleServerChildTcpSocket(ServerChildTcpSocket socket)
        {
            Socket = socket;

            // Create the receive buffer for the socket
            Packetizer = new SocketPacketProtocol(Socket);

            // Initialize the keepalive timer
            KeepaliveTimer          = new Timer();
            KeepaliveTimer.Elapsed += KeepaliveTimerTimeout;

            // Start reading
            Packetizer.Start();

            // Start writing keepalive packets as necessary
            KeepaliveTimer.SetPeriodic(TimeSpan.FromSeconds(5));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of <see cref="SimpleServerChildTcpSocket"/>.
        /// </summary>
        /// <param name="socket">The socket to wrap.</param>
        internal SimpleServerChildTcpSocket(ServerChildTcpSocket socket)
        {
            Socket = socket;

            // Create the receive buffer for the socket
            Packetizer = new SocketPacketProtocol(Socket);

            // Initialize the keepalive timer
            KeepaliveTimer = new Timer();
            KeepaliveTimer.Elapsed += KeepaliveTimerTimeout;

            // Start reading
            Packetizer.Start();

            // Start writing keepalive packets as necessary
            KeepaliveTimer.SetPeriodic(TimeSpan.FromSeconds(5));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of <see cref="SimpleClientTcpSocket"/>.
        /// </summary>
        public SimpleClientTcpSocket()
        {
            // Create the underlying socket and hook up its Connect event.
            Socket = new ClientTcpSocket();
            Socket.ConnectCompleted += SocketConnectCompleted;

            // Create the receive buffer for the socket.
            Packetizer = new SocketPacketProtocol(Socket);

            // Initialize the keepalive timer and its default value.
            KeepaliveTimer = new Timer();
            KeepaliveTimer.Elapsed += KeepaliveTimerTimeout;
            KeepaliveTimer.Interval = TimeSpan.FromSeconds(5);
        }
Exemplo n.º 5
0
 /// <inheritdoc />
 public void WriteAsync(byte[] packet, object state)
 {
     KeepaliveTimer.Restart();
     SocketPacketProtocol.WritePacketAsync(Socket, packet, state);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Responds to the keepalive timer's Timeout event.
 /// </summary>
 private void KeepaliveTimerTimeout()
 {
     SocketPacketProtocol.WriteKeepaliveAsync(Socket);
 }