Пример #1
0
        private static void ConnectCompleted(object sender, SocketAsyncEventArgs e)
        {
            var token        = (Tuple <Action <MessageServerClient>, Action <Exception> >)e.UserToken;
            var doOnFinished = token.Item1;
            var onError      = token.Item2;

            try
            {
                Console.WriteLine("Client connected");
                CheckEventArgsStatic(e);
#if NET2
                Socket socket = (Socket)sender;
#else
                Socket socket = e.ConnectSocket;
#endif
                MessageServerClient client = null;
                client = new MessageServerClient(socket);
                client.WaitForClientData();
                doOnFinished(client);
            }
            catch (ObjectDisposedException ex)
            {
                onError(ex);
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Unknown Error: {0}", TraceEventType.Critical, ex);
                onError(ex);
            }
            finally
            {
                e.Dispose();
            }
        }
Пример #2
0
        private MessageServerClient CreateNewClient(Socket clientSocket)
        {
            var client = new MessageServerClient(clientSocket);

            lock (this.connectedClientsLock)
            {
                this.connectedClients.Add(client);
            }
            client.Disconnected += this.OnClientDisconnected;
            return(client);
        }
Пример #3
0
 public ClientConnectedEventArgs(MessageServerClient connectedClient)
 {
     this.ConnectedClient = connectedClient;
 }
Пример #4
0
 private MessageServerClient CreateNewClient(Socket clientSocket)
 {
     var client = new MessageServerClient(clientSocket);
     lock (this.connectedClientsLock)
     {
         this.connectedClients.Add(client);
     }
     client.Disconnected += this.OnClientDisconnected;
     return client;
 }
Пример #5
0
 public SendPacket(byte[] bytesToSend, ParsedLineEventArgs eventArgs, Stream rawData, MessageServerClient client, bool disposeStream, long toSend)
 {
     this.BytesToSend   = bytesToSend;
     this.EventArgs     = eventArgs;
     this.RawData       = rawData;
     this.Client        = client;
     this.DisposeStream = disposeStream;
     this.ToSend        = toSend;
 }
Пример #6
0
 public SendPacket(byte[] bytesToSend, ParsedLineEventArgs eventArgs, Stream rawData, MessageServerClient client, bool disposeStream, long toSend)
 {
     this.BytesToSend = bytesToSend;
     this.EventArgs = eventArgs;
     this.RawData = rawData;
     this.Client = client;
     this.DisposeStream = disposeStream;
     this.ToSend = toSend;
 }
Пример #7
0
 private static void ConnectCompleted(object sender, SocketAsyncEventArgs e)
 {
     var token = (Tuple<Action<MessageServerClient>, Action<Exception>>)e.UserToken;
     var doOnFinished = token.Item1;
     var onError = token.Item2;
     try
     {
         Console.WriteLine("Client connected");
         CheckEventArgsStatic(e);
     #if NET2
         Socket socket = (Socket)sender;
     #else
         Socket socket = e.ConnectSocket;
     #endif
         MessageServerClient client = null;
         client = new MessageServerClient(socket);
         client.WaitForClientData();
         doOnFinished(client);
     }
     catch (ObjectDisposedException ex)
     {
         onError(ex);
     }
     catch (Exception ex)
     {
         Logger.WriteLine("Unknown Error: {0}", TraceEventType.Critical, ex);
         onError(ex);
     }
     finally
     {
         e.Dispose();
     }
 }
Пример #8
0
 public ClientConnectedEventArgs(MessageServerClient connectedClient)
 {
     this.ConnectedClient = connectedClient;
 }