Пример #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);
        }
Пример #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));
        }
Пример #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));
        }
Пример #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);
        }
Пример #5
0
 /// <inheritdoc />
 public void WriteAsync(byte[] packet, object state)
 {
     KeepaliveTimer.Restart();
     SocketPacketProtocol.WritePacketAsync(Socket, packet, state);
 }
Пример #6
0
 /// <summary>
 /// Responds to the keepalive timer's Timeout event.
 /// </summary>
 private void KeepaliveTimerTimeout()
 {
     SocketPacketProtocol.WriteKeepaliveAsync(Socket);
 }