C# Class AsyncSocketSample.Server

Implements the connection logic for the socket server. After accepting a connection, all data read from the client is sent back to the client. The read and echo back to the client pattern is continued until the client disconnects.
Datei anzeigen Open project: dlech/SshAgentLib Class Usage Examples

Public Methods

Method Description
Init ( ) : void

Initializes the server by preallocating reusable buffers and context objects. These objects do not need to be preallocated or reused, by is done this way to illustrate how the API can easily be used to create reusable objects to increase server performance.

Server ( int numConnections, int receiveBufferSize ) : System

Create an uninitialized server instance. To start the server listening for connection requests call the Init method followed by Start method

Start ( IPEndPoint localEndPoint ) : void

Starts the server such that it is listening for incoming connection requests.

StartAccept ( SocketAsyncEventArgs acceptEventArg ) : void

Begins an operation to accept a connection request from the client

Private Methods

Method Description
AcceptEventArg_Completed ( object sender, SocketAsyncEventArgs e ) : void

This method is the callback method associated with Socket.AcceptAsync operations and is invoked when an accept operation is complete

CloseClientSocket ( SocketAsyncEventArgs e ) : void
IO_Completed ( object sender, SocketAsyncEventArgs e ) : void

This method is called whenever a receive or send opreation is completed on a socket

ProcessAccept ( SocketAsyncEventArgs e ) : void
ProcessReceive ( SocketAsyncEventArgs e ) : void

This method is invoked when an asycnhronous receive operation completes. If the remote host closed the connection, then the socket is closed. If data was received then the data is echoed back to the client.

ProcessSend ( SocketAsyncEventArgs e ) : void

This method is invoked when an asynchronous send operation completes. The method issues another receive on the socket to read any additional data sent from the client

Method Details

Init() public method

Initializes the server by preallocating reusable buffers and context objects. These objects do not need to be preallocated or reused, by is done this way to illustrate how the API can easily be used to create reusable objects to increase server performance.
public Init ( ) : void
return void

Server() public method

Create an uninitialized server instance. To start the server listening for connection requests call the Init method followed by Start method
public Server ( int numConnections, int receiveBufferSize ) : System
numConnections int the maximum number of connections the sample is designed to handle simultaneously
receiveBufferSize int buffer size to use for each socket I/O operation
return System

Start() public method

Starts the server such that it is listening for incoming connection requests.
public Start ( IPEndPoint localEndPoint ) : void
localEndPoint System.Net.IPEndPoint The endpoint which the server will listening for conenction requests on
return void

StartAccept() public method

Begins an operation to accept a connection request from the client
public StartAccept ( SocketAsyncEventArgs acceptEventArg ) : void
acceptEventArg System.Net.Sockets.SocketAsyncEventArgs The context object to use when issuing the accept operation on the /// server's listening socket
return void