Exemplo n.º 1
0
        private void OnClientConnect(IAsyncResult result)
        {
            try
            {
                Socket clientSocket = Socket.EndAccept(result);

                /* WebClient c = new WebClient();
                 * c.DownloadStringCompleted +=
                 *  (sender, e) =>
                 *  {
                 *      Console.WriteLine("[UCS]    Client connected (" +
                 *                        ((IPEndPoint) clientSocket.RemoteEndPoint).Address + ", " + e.Result.Trim() +
                 *                        ")");
                 *  };
                 * c.DownloadStringAsync(
                 *  new Uri("http://ipinfo.io/" + ((IPEndPoint) clientSocket.RemoteEndPoint).Address + "/country"));
                 *
                 */
                Console.WriteLine("[UCS]    Client connected (" + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + ")");
                ResourcesManager.AddClient(new Client(clientSocket),
                                           ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString());
                SocketRead.Begin(clientSocket, OnReceive, OnReceiveError);
                Socket.BeginAccept(OnClientConnect, Socket);
            }
            catch (Exception e)
            {
                Debugger.WriteLine("[UCS]    Exception when accepting incoming connection", e);
            }
        }
Exemplo n.º 2
0
Arquivo: Gateway.cs Projeto: skwbr/UCS
 void OnClientConnect(IAsyncResult ar)
 {
     allDone.Set();
     try
     {
         Socket listener     = (Socket)ar.AsyncState;
         Socket clientSocket = listener.EndAccept(ar);
         _Logger.Print("[UCS]    Player connected -> " + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + "", Types.ERROR);
         ResourcesManager.AddClient(new Client(clientSocket), ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString());
         SocketRead.Begin(clientSocket, OnReceive, OnReceiveError);
     }
     catch (Exception e)
     {
     }
 }
Exemplo n.º 3
0
 void OnClientConnect(IAsyncResult ar)
 {
     allDone.Set();
     try
     {
         Socket listener     = (Socket)ar.AsyncState;
         Socket clientSocket = listener.EndAccept(ar);
         Console.WriteLine("[UCS]    Player connected " + ((IPEndPoint)clientSocket.RemoteEndPoint).Address + "");
         ResourcesManager.AddClient(new Client(clientSocket), ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString());
         SocketRead.Begin(clientSocket, OnReceive, OnReceiveError);
     }
     catch (Exception e)
     {
         //Debugger.WriteLine("[UCS]    Exception when accepting incoming connection", e);
     }
 }