Beispiel #1
0
 public void Stop()
 {
     if (Connected)
     {
         ses.Close();
         ses = null;
     }
 }
Beispiel #2
0
        private void NetSession_Closed(NetSession ses)
        {
            // Raise event to consumer
            ClientClosed?.Invoke(ses);

            lock (sessions)
            {
                sessions.Remove(ses.Id);
            }
            ses.Dispose();
        }
 private Client FindClientBySession(NetSession ses)
 {
     foreach (KeyValuePair <int, Client> kv in clients)
     {
         Client c = kv.Value;
         if (c.Session.Id == ses.Id)
         {
             return(c);
         }
     }
     return(null);
 }
        private void TCPServer_ClientClosed(NetSession ses)
        {
            string remoteInfo = ses.RemoteInfo;
            string id         = ses.Id.ToString();

            lock (clients)
            {
                clients.Remove(ses.Id);
            }

            string clientCount = clients.Count.ToString();

            Logger.Log("[QueueServer] Client ID: " + id + " closed, RemoteInfo: " + remoteInfo + ", Client left: " + clientCount);
        }
Beispiel #5
0
        private void NetSession_Closed(NetSession ses)
        {
            // Raise event to consumer
            if (ClientClosed != null)
            {
                ClientClosed(ses);
            }

            lock (sessions)
            {
                sessions.Remove(ses.Id);
            }
            ses.Dispose();
        }
Beispiel #6
0
        // Construct message from rawdata
        public Message(DataReceivedEventArgs arg)
        {
            _valid = false;

            string stringMessage = Encoding.UTF8.GetString(arg.Data);

            if (stringMessage != null)
            {
                _rawMessage = stringMessage;
            }

            _session = arg.Session;

            Parse();
        }
        private void TCPServer_ClientAccepted(NetSession ses)
        {
            string remoteInfo = ses.RemoteInfo;
            string id         = ses.Id.ToString();
            Client client     = new Client(ses);

            lock (clients)
            {
                clients.Add(ses.Id, client);
            }

            string clientCount = clients.Count.ToString();

            Logger.Log("[QueueServer] Client ID: " + id + " accepted, RemoteInfo: " + remoteInfo + ",  Total Client: " + clientCount);
        }
Beispiel #8
0
        public void Start()
        {
            if (!Connected)
            {
                Socket sock = GetSocket(mServer, mPort);

                if (sock != null)
                {
                    ses = new NetSession(sock);
                    ses.DataReceived += new DataReceived(NetSession_DataReceived);
                    ses.Notified     += new Action <NotifyEventArgs>(NetSession_Notified);
                    ses.BeginReceive();
                }
            }
        }
Beispiel #9
0
        //! Socket's BeginAccept() callback
        //  Handles new connection and create session
        private void AcceptCallback(IAsyncResult ar)
        {
            // our session
            NetSession ses = null;

            try
            {
                // Signal the main thread to continue.
                allDone.Set();

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

                if (CanConnect(ep))
                {
                    // setup the session
                    ses = new NetSession(handler)
                    {
                        Id = NewSessionId()
                    };

                    // bind session event handler
                    ses.Notified         += new Action <NotifyEventArgs>(NetSession_Notified);
                    ses.ConnectionClosed += new ConnectionClosed(NetSession_Closed);
                    ses.DataReceived     += new DataReceived(NetSession_DataReceived);

                    ses.BeginReceive();

                    // add session to our table
                    lock (sessions)
                    {
                        sessions.Add(ses.Id, ses);
                    }

                    // Call ClientAccepted handler
                    ClientAccepted?.Invoke(ses);
                }
                else
                {
                    handler.Shutdown(SocketShutdown.Both);
                    handler.Close();
                }

                // start listen for connections again.
                listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
            }
            catch (SocketException e)
            {
                if (ses != null)
                {
                    ses.Close();
                }

                // Queue the next accept, think this should be here, stop attacks based on killing the waiting listeners
                if (sock != null)
                {
                    sock.BeginAccept(new AsyncCallback(AcceptCallback), sock);
                }
            }
            catch (Exception e)
            {
                if (ses != null)
                {
                    ses.Close();
                }

                // Queue the next accept, think this should be here, stop attacks based on killing the waiting listeners
                if (sock != null)
                {
                    sock.BeginAccept(new AsyncCallback(AcceptCallback), sock);
                }
            }
        }
Beispiel #10
0
 public DataReceivedEventArgs(NetSession ses, byte[] data)
 {
     _session = ses;
     _data    = data;
 }
Beispiel #11
0
 public Client(NetSession ses)
 {
     session = ses;
     cType   = ClientType.QueueCaller;
 }