示例#1
0
 public void AddClient(TCPClientConnection client)
 {
     lock (fAddRemoveUsersLock)
     {
         try
         {
             if (!fConnectedClients.ContainsKey(client.IPAddress))
             {
                 fConnectedClients.Add(client.IPAddress, client);
             }
         }
         catch (Exception ex)
         {
         }
     }
 }
示例#2
0
 /// <summary>
 /// Send data to all connected clients excepts sender.
 /// </summary>
 /// <param name="bytes">The byte array to be send.</param>
 /// <param name="offset">The position in the data buffer at witch to begin sending.</param>
 /// <param name="length">The number of the bytes to be send.</param>
 /// <param name="sender">The TCP client exception.</param>
 public void ReplyToAllExceptSender(byte[] bytes, int offset, int length, TCPClientConnection sender)
 {
     if (sender != null)
     {
         foreach (DictionaryEntry entry in fConnectedClients)
         {
             try
             {
                 TCPClientConnection tmp = (TCPClientConnection)entry.Value;
                 if (tmp.IPAddress != sender.IPAddress)
                 {
                     tmp.SendData(bytes, offset, length);
                 }
             }
             catch (Exception ex)
             {
             }
         }
     }
 }
示例#3
0
 /// <summary>
 /// Send data to all connected clients excepts sender.
 /// </summary>
 /// <param name="data">The string to be send.</param>
 /// <param name="sender">The TCP client exception.</param>
 public void ReplyToAllExceptSender(string data, TCPClientConnection sender)
 {
     if (sender != null)
     {
         foreach (DictionaryEntry entry in fConnectedClients)
         {
             try
             {
                 TCPClientConnection tmp = (TCPClientConnection)entry.Value;
                 if (tmp.IPAddress != sender.IPAddress)
                 {
                     tmp.SendData(data);
                 }
             }
             catch (Exception ex)
             {
             }
         }
     }
 }
示例#4
0
        private void DoAcceptSocketCallback(IAsyncResult ar)
        {
            if (fThreadIsRunning)
            {
                try
                {
                    TcpListener listener = (TcpListener)ar.AsyncState;

                    TCPClientConnection client = new TCPClientConnection(listener.EndAcceptSocket(ar), fMyListener, fMyListener.IsMessageCollectorInUse, fMyListener.MessageSplitter);
                    if (fMyListener.ConnectedClients.Count >= fMyListener.MaxConnections)
                    {
                        client.DisconnectMe();
                    }
                }
                catch (Exception ex)
                {
                }

                DoListen();
            }
        }
示例#5
0
        private void DoAcceptSocketCallback(IAsyncResult ar)
        {
            if (fThreadIsRunning)
            {
                try
                {
                    TcpListener listener = (TcpListener)ar.AsyncState;

                    TCPClientConnection client = new TCPClientConnection(listener.EndAcceptSocket(ar), fMyListener, fMyListener.IsMessageCollectorInUse, fMyListener.MessageSplitter);
                    fClientConnectionCompleted.Set();

                    if (fMyListener.ConnectedClients.Count >= fMyListener.MaxConnections)
                    {
                        client.DisconnectMe();
                    }
                }
                catch (Exception ex)
                {
                }

                DoListen();
            }
        }
示例#6
0
 public void AddClient(TCPClientConnection client)
 {
     lock (fAddRemoveUsersLock)
     {
         try
         {
             if (!fConnectedClients.ContainsKey(client.IPAddress))
             {
                 fConnectedClients.Add(client.IPAddress, client);
             }
         }
         catch (Exception ex)
         {
         }
     }
 }
示例#7
0
        /// <summary>
        /// Send data to all connected clients excepts sender.
        /// </summary>
        /// <param name="bytes">The byte array to be send.</param>
        /// <param name="offset">The position in the data buffer at witch to begin sending.</param>
        /// <param name="length">The number of the bytes to be send.</param>
        /// <param name="sender">The TCP client exception.</param>
        public void ReplyToAllExceptSender(byte[] bytes, int offset, int length, TCPClientConnection sender)
        {
            if (sender != null)
            {
                foreach (DictionaryEntry entry in fConnectedClients)
                {
                    try
                    {
                        TCPClientConnection tmp = (TCPClientConnection)entry.Value;
                        if (tmp.IPAddress != sender.IPAddress)
                        {
                            tmp.SendData(bytes,offset,length);
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }
示例#8
0
        /// <summary>
        /// Send data to all connected clients excepts sender.
        /// </summary>
        /// <param name="data">The string to be send.</param>
        /// <param name="sender">The TCP client exception.</param>
        public void ReplyToAllExceptSender(string data, TCPClientConnection sender)
        {
            if (sender != null)
            {
                foreach (DictionaryEntry entry in fConnectedClients)
                {
                    try
                    {
                        TCPClientConnection tmp = (TCPClientConnection)entry.Value;
                        if (tmp.IPAddress != sender.IPAddress)
                        {
                            tmp.SendData(data);
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }
示例#9
0
 /// <summary>
 /// Send data to all connected clients excepts sender.
 /// </summary>
 /// <param name="bytes">The byte array to be send.</param>
 /// <param name="offset">The position in the data buffer at witch to begin sending.</param>
 /// <param name="length">The number of the bytes to be send.</param>
 /// <param name="sender">The TCP client exception.</param>
 public virtual void ReplyToAllExceptSender(byte[] bytes, int offset, int length, TCPClientConnection sender)
 {
     for (int i = 0; i < fListeners.Count; i++)
     {
         try
         {
             ((TCPListener)fListeners[i]).ReplyToAllExceptSender(bytes,offset,length, sender);
         }
         catch (Exception ex)
         {
         }
     }
 }
示例#10
0
 /// <summary>
 /// Send data to all connected clients excepts sender.
 /// </summary>
 /// <param name="data">The string to be send.</param>
 /// <param name="sender">The TCP client exception.</param>
 public virtual void ReplyToAllExceptSender(string data, TCPClientConnection sender)
 {
     for (int i = 0; i < fListeners.Count; i++)
     {
         try
         {
             ((TCPListener)fListeners[i]).ReplyToAllExceptSender(data,sender);
         }
         catch (Exception ex)
         {
         }
     }
 }
示例#11
0
 /// <summary>
 /// Send data to a client.
 /// </summary>
 /// <param name="bytes">The byte array to be send.</param>
 /// <param name="offset">The position in the data buffer at witch to begin sending.</param>
 /// <param name="length">The number of the bytes to be send.</param>
 /// <param name="sender">The client to send the data.</param>
 public virtual void ReplyToSender(byte[] bytes, int offset, int length, TCPClientConnection sender)
 {
     sender.SendData(bytes, offset, length);
 }
示例#12
0
 /// <summary>
 /// Send data to a client.
 /// </summary>
 /// <param name="data">The string to send.</param>
 /// <param name="sender">The client to send the data.</param>
 public virtual void ReplyToSender(string data, TCPClientConnection sender)
 {
     sender.SendData(data);
 }
示例#13
0
 /// <summary>
 /// A client disconnects from this server.
 /// </summary>
 /// <param name="client"></param>
 public virtual void OnClientDisconnect(TCPClientConnection client)
 {
 }
示例#14
0
 /// <summary>
 /// Server is receiving data from a client connection.
 /// </summary>
 /// <param name="sender">The client sends the data to this server.</param>
 /// <param name="data">The incoming DataFrame.</param>
 public virtual void OnDataReceive(TCPClientConnection sender, DataFrame data)
 {
 }