예제 #1
0
 private void Send(Client client, String data)
 {
     var byteData = Encoding.ASCII.GetBytes(data);
     try
     {
         client.socket.BeginSend(byteData, 0, byteData.Length, 0,
                                 new AsyncCallback(SendCallback), client);
     }
     catch (SocketException)
     {
         ClientRemove(client);
     }
 }
예제 #2
0
        private void ClientCallback(IAsyncResult ar)
        {
            signal.Set();

            try
            {
                var socketServer = (Socket)ar.AsyncState;
                var socketClient = socketServer.EndAccept(ar);
                var addr = GetHostName(socketClient.RemoteEndPoint.ToString());

                if (clients.Count < MAX_CLIENTS)
                {
                    var client = new Client(socketClient);
                    ClientAdd(client);
                    callback(new ServerStatus(
                        String.Format(Resources._0Connected, addr)));
                    UpdateCount();
                }
                else{
                    socketClient.Send(warnMaxClients);
                    socketClient.Shutdown(SocketShutdown.Both);
                    socketClient.Close();
                    callback(new ServerStatus(
                        String.Format(Resources._0RefusedTooManyConnections, addr)));
                }
            }
            catch (ObjectDisposedException) { }
        }
예제 #3
0
 private void ClientRemove(Client client)
 {
     lock (lockClients)
         clients.Remove(client);
     var addr = GetHostName(client.socket.RemoteEndPoint.ToString());
     client.socket.Shutdown(SocketShutdown.Both);
     client.socket.Close();
     callback(new ServerStatus(String.Format(Resources._0Disconnected, addr)));
     UpdateCount();
 }
예제 #4
0
 private void ClientAdd(Client client)
 {
     lock (lockClients)
         clients.Add(client);
 }