C# Class P2PStateServer.ServiceSocket

Represents an exception-safe wrapper of the .NET socket class. It exposes asynchronous methods and properties useful for state server soket operations.
The .NET Socket class is thread-safe but you can never be too careful. This class introduces an extra synchronization layer.
显示文件 Open project: tenor/p2pStateServer Class Usage Examples

Public Methods

Method Description
Abort ( ) : void

Terminates a connection

BeginConnect ( string Host, int Port, AsyncCallback ConnectCallBack, object StateObject ) : IAsyncResult

Begins an asynchronous Connect

BeginReceive ( int BufferLength, AsyncCallback ReadCallBack, object StateObject ) : IAsyncResult

Begins an asynchronous receive

CheckConnection ( ) : bool

Returns a value which indicates whether the socket is still connected.

This method actively checks the connection status by sending a zero-sized payload packet to inbound sockets or calling Socket.Poll for outbound sockets.

Close ( ) : void

Closes the socket gracefully

EndConnect ( IAsyncResult ar ) : void

Ends an asynchronous Connect

EndReceive ( IAsyncResult ar, bool &Error ) : byte[]

Ends an asynchronous Receive

Equals ( object obj ) : bool
GetHashCode ( ) : int
Listen ( int Port, AsyncCallback AcceptCallback ) : Socket

Listens on a specified port on the machine

Send ( ResponseData Message ) : void

Sends data via the socket asynchronously

ServiceSocket ( Socket socket, bool IsPeerSocket, IBufferPool Buffers ) : System

Initializes a new instance of the ServiceSocket class.

ServiceSocket ( bool IsPeerSocket, IBufferPool Buffers ) : System

Initializes a new instance of the ServiceSocket class.

Private Methods

Method Description
CompleteSend ( IAsyncResult ar ) : void

Completes an asynchronous send

ServiceSocket ( ) : System

Method Details

Abort() public method

Terminates a connection
public Abort ( ) : void
return void

BeginConnect() public method

Begins an asynchronous Connect
public BeginConnect ( string Host, int Port, AsyncCallback ConnectCallBack, object StateObject ) : IAsyncResult
Host string Host to connect to
Port int Port number to connect to
ConnectCallBack AsyncCallback Callback to call on connecting
StateObject object State object to pass to ConnectCallback
return IAsyncResult

BeginReceive() public method

Begins an asynchronous receive
public BeginReceive ( int BufferLength, AsyncCallback ReadCallBack, object StateObject ) : IAsyncResult
BufferLength int
ReadCallBack AsyncCallback Method to call on receiving data
StateObject object State object to be passed to ReadCallBack
return IAsyncResult

CheckConnection() public method

Returns a value which indicates whether the socket is still connected.
This method actively checks the connection status by sending a zero-sized payload packet to inbound sockets or calling Socket.Poll for outbound sockets.
public CheckConnection ( ) : bool
return bool

Close() public method

Closes the socket gracefully
public Close ( ) : void
return void

EndConnect() public method

Ends an asynchronous Connect
public EndConnect ( IAsyncResult ar ) : void
ar IAsyncResult AsyncResult obtained from BeginConnect
return void

EndReceive() public method

Ends an asynchronous Receive
public EndReceive ( IAsyncResult ar, bool &Error ) : byte[]
ar IAsyncResult AsyncResult obtained from BeginReive
Error bool Indicates an error occured while receiving data
return byte[]

Equals() public method

public Equals ( object obj ) : bool
obj object
return bool

GetHashCode() public method

public GetHashCode ( ) : int
return int

Listen() public static method

Listens on a specified port on the machine
public static Listen ( int Port, AsyncCallback AcceptCallback ) : Socket
Port int Port number
AcceptCallback AsyncCallback Callback for accepting new connections
return Socket

Send() public method

Sends data via the socket asynchronously
public Send ( ResponseData Message ) : void
Message ResponseData Data to transmit
return void

ServiceSocket() public method

Initializes a new instance of the ServiceSocket class.
public ServiceSocket ( Socket socket, bool IsPeerSocket, IBufferPool Buffers ) : System
socket Socket The .NET Socket object to encapsulate
IsPeerSocket bool Indicates if this socket was spawned from the state server peer port
Buffers IBufferPool
return System

ServiceSocket() public method

Initializes a new instance of the ServiceSocket class.
public ServiceSocket ( bool IsPeerSocket, IBufferPool Buffers ) : System
IsPeerSocket bool Indicates if this socket was spawned from the state server peer port
Buffers IBufferPool
return System