Exemple #1
0
        /// <summary>
        /// Works the specified data.
        /// </summary>
        /// <param name="data">The specified data.</param>
        protected void Worker(object data)
        {
            ConnectionManagerThreadArgs args = (ConnectionManagerThreadArgs)data;

            while (!args.Stop)
            {
                try
                {
                    EnhancedTcpClient client = new EnhancedTcpClient(this.tcpListener.AcceptTcpClient());

                    if (client.Connected)
                    {
                        TcpConnection connection = new TcpConnection(client);
                        connection.MessageReceived += this.FireMessageReceived;
                        connection.RawDataReceived += this.FireRawDataReceived;
                        connection.ConnectionLost  += this.Connection_Disconnected;
                        connection.TimedOut        += this.Connection_Disconnected;
                        connection.TimeoutLimit     = this.TimeoutLimit;
                        this.Connections.Add(connection);
                        this.FireClientAccepted(this, new ClientAcceptedEventArgs(connection));
                        connection.StartListening();
                    }
                }
                catch (SocketException)
                {
                    // Exception occurs on closing the connection manger.
                }

                Thread.Sleep(args.PollDelay);
            }
        }
Exemple #2
0
        /// <summary>
        /// Sends the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="enhancedTcpClient">The enhanced TCP client.</param>
        /// <exception cref="ArgumentNullException">
        /// Is thrown if either of the values is null:
        /// message - The value must not be null.
        /// or
        /// enhancedTCPClient - The value must not be null.
        /// </exception>
        public static void Send(object message, EnhancedTcpClient enhancedTcpClient)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message), "The value must not be null.");
            }

            if (enhancedTcpClient == null)
            {
                throw new ArgumentNullException(nameof(enhancedTcpClient), "The value must not be null.");
            }

            enhancedTcpClient.Write(Serialize(new MessageContainer(message)));
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TcpConnection"/> class.
 /// </summary>
 /// <param name="enhancedTcpClient">An enhanced TCP client.</param>
 public TcpConnection(EnhancedTcpClient enhancedTcpClient)
 {
     this.EnhancedTcpClient = enhancedTcpClient;
     this.EnhancedTcpClient.ConnectionFailed += this.FireConnectionFailed;
     this.EnhancedTcpClient.ConnectionLost   += this.FireConnectionLost;
 }