コード例 #1
0
        private void Accept_Completed(object sender, SocketAsyncEventArgs e)
        {
            e.Completed -= Accept_Completed;

            if (e.SocketError != SocketError.Success)
            {
                var error = string.Format("There was an error accepting a socket connection ({0}).",
                    Enum.GetName(typeof(SocketError), e.SocketError));
                OnConnectionAccepted(new ConnectionAcceptedEventArgs(error));
                return;
            }

            var clientConnection = new ClientConnection(e.AcceptSocket);
            try
            {
                OnConnectionAccepted(new ConnectionAcceptedEventArgs(clientConnection));
                clientConnection.ShutdownAndClose();
            }
            finally
            {
                ((IDisposable)clientConnection).Dispose();
            }

            OnConnectionClosed();
            AcceptIncomingConnection();
        }
コード例 #2
0
ファイル: ServerController.cs プロジェクト: jprice628/Sketch
 private Image ReceiveImageData(ClientConnection clientConnection)
 {
     var numRows = clientConnection.ReceiveInt32();
     var numColumns = clientConnection.ReceiveInt32();
     var pixels = clientConnection.ReceiveBytes(numRows * numColumns);
     mainWindow.WriteLine("Received {0} pixels in {1} rows and {2} columns.", pixels.Length, numRows, numColumns);
     return imageDataTransformer.Transform(numRows, numColumns, pixels);
 }
コード例 #3
0
 public ConnectionAcceptedEventArgs(ClientConnection clientConnection)
 {
     this.Error = null;
     this.ClientConnection = clientConnection;
 }