Ejemplo n.º 1
0
 void OnReceiveError(SocketRead read, System.Exception exception)
 {
     //Dev View
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine("Error received: " + exception);
     Console.ResetColor();
 }
Ejemplo n.º 2
0
        private void OnReceive(IAsyncResult result)
        {
            try
            {
                if (result.IsCompleted)
                {
                    int bytesRead = this.socket.EndReceive(result);

                    if (bytesRead > 0)
                    {
                        byte[] read = new byte[bytesRead];
                        Array.Copy(this.buffer, 0, read, 0, bytesRead);

                        this.readHandler(this, read);
                        SocketRead.Begin(this.socket, this.readHandler, this.errorHandler);
                    }
                    else
                    {
                        // Disconnect
                    }
                }
            }
            catch (Exception e)
            {
                if (this.errorHandler != null)
                {
                    this.errorHandler(this, e);
                }
            }
        }
Ejemplo n.º 3
0
 private void OnClientConnect(IAsyncResult result)
 {
     try
     {
         var clientSocket = Socket.EndAccept(result);
         ResourcesManager.AddClient(new Client(clientSocket),
                                    ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString());
         SocketRead.Begin(clientSocket, OnReceive, OnReceiveError);
         Console.WriteLine("[UCS]    Client connected (" + ((IPEndPoint)clientSocket.RemoteEndPoint).Address +
                           ":" +
                           ((IPEndPoint)clientSocket.RemoteEndPoint).Port + ")");
     }
     catch (Exception e)
     {
         Console.WriteLine("[UCS]    Exception when accepting incoming connection: " + e);
     }
     try
     {
         Socket.BeginAccept(OnClientConnect, Socket);
     }
     catch (Exception e)
     {
         Console.WriteLine("[UCS]    Exception when starting new accept process: " + e);
     }
 }
Ejemplo n.º 4
0
 void OnClientConnect(System.IAsyncResult result)
 {
     try
     {
         Socket clientSocket = m_vServerSocket.EndAccept(result);
         Debugger.WriteLine("[M] Client connected (" + ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString() + ":" + ((IPEndPoint)clientSocket.RemoteEndPoint).Port.ToString() + ")");
         ResourcesManager.AddClient(new Client(clientSocket));
         SocketRead.Begin(clientSocket, OnReceive, OnReceiveError);
     }
     catch (System.Exception e)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Exception when accepting incoming connection: " + e);
         Console.ResetColor();
     }
     try
     {
         m_vServerSocket.BeginAccept(new System.AsyncCallback(OnClientConnect), m_vServerSocket);
     }
     catch (System.Exception e)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Exception when starting new accept process: " + e);
         Console.ResetColor();
     }
 }
Ejemplo n.º 5
0
 private void OnReceive(SocketRead read, byte[] data)
 {
     try
     {
         var socketHandle = read.Socket.Handle.ToInt64();
         var c            = ResourcesManager.GetClient(socketHandle);
         c.DataStream.AddRange(data);
         Message p;
         while (c.TryGetPacket(out p))
         {
             PacketManager.ProcessIncomingPacket(p);
         }
     }
     catch (Exception ex)
     {
         Debugger.WriteLine("Error when receiving packet from client : ", ex, 4, ConsoleColor.Red);
     }
 }
Ejemplo n.º 6
0
        private static void OnReceive(SocketRead read, byte[] data)
        {
            try
            {
                var socketHandle = read.Socket.Handle.ToInt64();
                var c            = ResourcesManager.GetClient(socketHandle);
                c.DataStream.AddRange(data);

                Message p;
                while (c.TryGetPacket(out p))
                {
                    PacketManager.ProcessIncomingPacket(p);
                }
            }
            catch (Exception ex)
            {
                Debugger.WriteLine("[UCR]   Exception thrown when processing incoming packet : ", ex);
            }
        }
Ejemplo n.º 7
0
        void OnReceive(SocketRead read, byte[] data)
        {
            try
            {
                long   socketHandle = read.Socket.Handle.ToInt64();
                Client c            = ResourcesManager.GetClient(socketHandle);
                //Ajoute les données au stream client
                c.DataStream.AddRange(data);

                Message p;
                while (c.TryGetPacket(out p))
                {
                    PacketManager.ProcessIncomingPacket(p);
                }
            }
            catch (Exception)
            {
                //Client may not exist anymore
            }
        }
Ejemplo n.º 8
0
        void OnReceive(SocketRead read, byte[] data)
        {
            
            try
            {
                long socketHandle = read.Socket.Handle.ToInt64();
                Client c = ResourcesManager.GetClient(socketHandle);
                    //Ajoute les données au stream client
                c.DataStream.AddRange(data);

                Message p;
                while (c.TryGetPacket(out p))
                {
                    PacketManager.ProcessIncomingPacket(p);
                }
            }
            catch(Exception)
            {
                //Client may not exist anymore
            }
        }
Ejemplo n.º 9
0
        private void ProcessAccept(SocketAsyncEventArgs args)
        {
            if (args.SocketError != SocketError.Success)
            {
                StartAccept(); // start to accept as soon as possible
                ProcessBadAccept(args);
                return;
            }

            StartAccept(); // start to accept as soon as possible

            var connection     = args.AcceptSocket;
            var remoteEndPoint = (IPEndPoint)connection.RemoteEndPoint;

            ResourcesManager.AddClient(new Client(connection));
            SocketRead.Begin(connection, OnReceive, OnReceiveError);

            Console.WriteLine("Client connected ({0}:{1})", remoteEndPoint.Address, remoteEndPoint.Port);

            args.AcceptSocket = null;
            _acceptPool.Push(args);
        }
Ejemplo n.º 10
0
 private void OnReceive(IAsyncResult result)
 {
     try
     {
         if (result.IsCompleted)
         {
             int num = this.Socket.EndReceive(result);
             if (num > 0)
             {
                 byte[] array = new byte[num];
                 Array.Copy(this.buffer, 0, array, 0, num);
                 this.readHandler(this, array);
                 SocketRead.Begin(this.Socket, this.readHandler, this.errorHandler);
             }
         }
     }
     catch (Exception exception)
     {
         if (this.errorHandler != null)
         {
             this.errorHandler(this, exception);
         }
     }
 }
Ejemplo n.º 11
0
 private static void OnReceiveError(SocketRead read, Exception exception)
 {
 }
Ejemplo n.º 12
0
 private void OnReceiveError(SocketRead read, Exception exception)
 {
     Debugger.WriteLine("Error received: " + exception, null, 5);
 }
Ejemplo n.º 13
0
 void OnReceiveError(SocketRead read, System.Exception exception)
 {
     //Console.WriteLine("Error received: " + exception);
 }
Ejemplo n.º 14
0
 void OnReceiveError(SocketRead read, System.Exception exception)
 {
     //Dev View
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine("Error received: " + exception);
     Console.ResetColor();
 }
Ejemplo n.º 15
0
 void OnReceiveError(SocketRead read, System.Exception exception)
 {
     //Console.WriteLine("Error received: " + exception);
 }