예제 #1
0
        public static void AcceptCallback(IAsyncResult ar)
        {
            // Signal the main thread to continue.
            AllDone.Set();

            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;
            Socket handler  = listener.EndAccept(ar);

            // Create the state object.
            StateObject state = new StateObject();

            state.workSocket = handler;

            Client client = new Client(ClientController.GetClientListCount());

            client.ConnectionTime = DateTime.Now;
            client.IP             = Convert.ToString(IPAddress.Parse(((IPEndPoint)state.workSocket.RemoteEndPoint).Address.ToString()));
            client.Port           = ((IPEndPoint)state.workSocket.RemoteEndPoint).Port;
            ClientController.AddClient(client);

            IPEndPoint clientEndPoint = (IPEndPoint)state.workSocket.RemoteEndPoint;

            Sistem.printF(string.Format("Client Connected: {0}", clientEndPoint.Address.ToString()), ConsoleColor.Green);

            handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
        }
예제 #2
0
파일: Hub.cs 프로젝트: gonsovsky/agentProto
        public void AcceptCallback(IAsyncResult ar)
        {
            AllDone.Set();
            var listener = (Socket)ar.AsyncState;
            var handler  = listener.EndAccept(ar);
            var state    = new HubState(Config, Fs)
            {
                WorkSocket = handler
            };

            handler.BeginReceive(state.Buffer, 0, Config.BufferSize, 0,
                                 ReadCallback, state);
        }
예제 #3
0
        protected override void AcceptCallback(IAsyncResult ar)
        {
            // Signal the main thread to continue.
            AllDone.Set();

            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;
            Socket handler  = listener.EndAccept(ar);

            // Create the ClientState object and begin recieving data
            ClientState client = new ClientState();

            client.WorkSocket = handler;

            // Recieve the upgrade request in an async recieve callback
            handler.BeginReceive(client.buffer, 0, ClientState.BufferSize,
                                 0, new AsyncCallback(Handshake), client);

            OnClientConnect(client);
        }
예제 #4
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            var state = (AgentState)ar.AsyncState;

            try
            {
                var client    = state.WorkSocket;
                var bytesRead = client.EndReceive(ar);
                if (bytesRead > 0)
                {
                    state.Receive(bytesRead);
                    client.BeginReceive(state.Buffer, 0, Config.BufferSize, 0,
                                        ReceiveCallback, state);
                }
                else
                {
                    AllDone.Set();
                }
            }
            catch (Exception e)
            {
                Abort(state, e);
            }
        }
예제 #5
0
 public static void Terminate()
 {
     _running = false;
     AllDone.Set();
 }