Sylloge
A C# helper library
Public Types | Public Member Functions | Protected Member Functions | Properties | Events
Sylloge.Net.Socket Class Reference

Provides a custom. More...

Inherited by Sylloge.Net.TcpSocket, and Sylloge.Net.UdpSocket.

List of all members.

Public Types

enum  KeepAliveType { NONE, CUSTOM, TCP }
 Defines the keep alive handling to use. More...

Public Member Functions

delegate void DelegateDataReceived (byte[] data)
 Represents the method that handles when the socket received data.
delegate void DelegateSocketError (System.Exception ex)
 Represents the method to receive the socket error.
delegate void DelegateConnectionCloseError (System.Exception ex)
 Represents the method that will handle when a connection is closed.
 Socket ()
 The defualt constructor.
 Socket (string ipAddress, int port)
 Create an instance of a Connectino class using a specific IP and port.
virtual Sylloge.Net.Socket Copy ()
 Create a deep copy of the current connection.
void Dispose ()
 Closes the current connection and cleans up.
void Flush ()
 Flush any buffered data on the stream.
void Initialize ()
 Initialize the basic variables.
void Shutdown ()
 Disconect and close the sockets and streams.
override string ToString ()
 Returs the IP and port in a string representation.
abstract void Close ()
 This method must be overridden in a derived class.
abstract void Connect (Socket.KeepAliveType type=KeepAliveType.NONE, byte[] msg=null, int msInterval=0)
 This method must be overridden in a derived class.
abstract void Listen ()
 This method must be overridden in a derived class.
abstract void Send (byte[] data)
 This method must be overridden in a derived class.

Protected Member Functions

void OnDataReceived (byte[] data)
 Called when data is recieved.
void OnSocketError (System.Exception ex)
 Called on an unrecoverable socket error.
void OnConnectionCloseError (System.Exception ex)
 Called on a connection closed error.
void Configure (KeepAliveType type, byte[] msg, int msInterval)
 This method should be called after a called to an overridden Connect method.

Properties

System.IAsyncResult m_AsyncResult [get, set]
 The async result of the socket communcation operation.
System.Windows.Forms.Timer m_KeepAlive [get, set]
 A keep alive timer that can be used to send custom keep alive messages.
System.Threading.Thread m_ListenThread [get, set]
 The listener thread for a client.
byte[] m_Msg [get, set]
 The custom keep alive message if m_Type == CUSTOM.
KeepAliveType m_KeepAliveType [get, set]
 The keep alive message type.
bool IsClosing [get, set]
 Gets if the current sockets are closing.
bool IsConnected [get, set]
 Gets if the socket is connected.
bool IsLocalHost [get, set]
 Gets if the socket/connection is the local host.
string IpAddress [get, set]
 Gets or sets the IP address to use.
bool IsRunning [get, set]
 Gets if thread is running.
int Port [get, set]
 Gets or sets the port used for the sockets.
System.Net.Sockets.Socket Handle [get, set]
 The underlying socket used to make the connections.
System.Net.Sockets.NetworkStream Stream [get, set]
 The underlying stream used to read and write data.
string IpAndPortString [get]
 Gets a string representation of the IP and port in use.

Events

DelegateDataReceived DataReceived
 Occurs when data is received on the listening socket.
DelegateSocketError SocketError
 Occurs when a internal socket error happens.
DelegateConnectionCloseError ConnectionCloseError
 Occurs when there is an error trying to close the connection.

Detailed Description

Provides a custom.

Definition at line 40 of file Socket.cs.


Member Enumeration Documentation

Defines the keep alive handling to use.

Enumerator:
NONE 

Don't set/use any keep alives.

CUSTOM 

Send a custom keep alive message.

TCP 

Set the keep alive TCP option.

Definition at line 45 of file Socket.cs.


Constructor & Destructor Documentation

Sylloge.Net.Socket.Socket ( )

The defualt constructor.

Definition at line 185 of file Socket.cs.

Sylloge.Net.Socket.Socket ( string  ipAddress,
int  port 
)

Create an instance of a Connectino class using a specific IP and port.

Parameters:
ipAddressThe IP address to use
portThe port to use

Definition at line 195 of file Socket.cs.


Member Function Documentation

abstract void Sylloge.Net.Socket.Close ( ) [pure virtual]

This method must be overridden in a derived class.

Implemented in Sylloge.Net.TcpSocket, and Sylloge.Net.UdpSocket.

void Sylloge.Net.Socket.Configure ( KeepAliveType  type,
byte[]  msg,
int  msInterval 
) [protected]

This method should be called after a called to an overridden Connect method.

Parameters:
typeThe keep alive type to use
msgThe custom keep alive message to send
msIntervalThe interval to send custom keep alive messages at

Definition at line 231 of file Socket.cs.

abstract void Sylloge.Net.Socket.Connect ( Socket.KeepAliveType  type = KeepAliveType.NONE,
byte[]  msg = null,
int  msInterval = 0 
) [pure virtual]

This method must be overridden in a derived class.

Parameters:
typeThe keep alive type to use (defualt NONE)
msgThe custom keep alive message to send (default null)
msIntervalThe interval to send custom keep alive messages at (default 0)

Implemented in Sylloge.Net.TcpSocket, and Sylloge.Net.UdpSocket.

virtual Sylloge.Net.Socket Sylloge.Net.Socket.Copy ( ) [virtual]

Create a deep copy of the current connection.

Returns:
A reference to the copied object

Reimplemented in Sylloge.Net.TcpSocket, and Sylloge.Net.UdpSocket.

Definition at line 214 of file Socket.cs.

delegate void Sylloge.Net.Socket.DelegateConnectionCloseError ( System.Exception  ex)

Represents the method that will handle when a connection is closed.

Parameters:
exThe System.Exception that occured
delegate void Sylloge.Net.Socket.DelegateDataReceived ( byte[]  data)

Represents the method that handles when the socket received data.

Parameters:
dataThe data received
delegate void Sylloge.Net.Socket.DelegateSocketError ( System.Exception  ex)

Represents the method to receive the socket error.

Parameters:
exThe System.Exception that occured
void Sylloge.Net.Socket.Dispose ( )

Closes the current connection and cleans up.

Definition at line 245 of file Socket.cs.

void Sylloge.Net.Socket.Flush ( )

Flush any buffered data on the stream.

Definition at line 253 of file Socket.cs.

void Sylloge.Net.Socket.Initialize ( )

Initialize the basic variables.

Definition at line 261 of file Socket.cs.

abstract void Sylloge.Net.Socket.Listen ( ) [pure virtual]

This method must be overridden in a derived class.

Implemented in Sylloge.Net.TcpSocket, and Sylloge.Net.UdpSocket.

void Sylloge.Net.Socket.OnConnectionCloseError ( System.Exception  ex) [protected]

Called on a connection closed error.

Parameters:
exThe System.Exception that occured

Definition at line 115 of file Socket.cs.

void Sylloge.Net.Socket.OnDataReceived ( byte[]  data) [protected]

Called when data is recieved.

Parameters:
dataThe data received

Definition at line 97 of file Socket.cs.

void Sylloge.Net.Socket.OnSocketError ( System.Exception  ex) [protected]

Called on an unrecoverable socket error.

Parameters:
exThe System.Exception that occured

Definition at line 106 of file Socket.cs.

abstract void Sylloge.Net.Socket.Send ( byte[]  data) [pure virtual]

This method must be overridden in a derived class.

Parameters:
dataThe data to send

Implemented in Sylloge.Net.TcpSocket, and Sylloge.Net.UdpSocket.

void Sylloge.Net.Socket.Shutdown ( )

Disconect and close the sockets and streams.

Definition at line 287 of file Socket.cs.

override string Sylloge.Net.Socket.ToString ( )

Returs the IP and port in a string representation.

Returns:

Reimplemented in Sylloge.Net.TcpSocket, and Sylloge.Net.UdpSocket.

Definition at line 328 of file Socket.cs.


Property Documentation

System.Net.Sockets.Socket Sylloge.Net.Socket.Handle [get, set]

The underlying socket used to make the connections.

Definition at line 172 of file Socket.cs.

string Sylloge.Net.Socket.IpAddress [get, set]

Gets or sets the IP address to use.

Definition at line 160 of file Socket.cs.

string Sylloge.Net.Socket.IpAndPortString [get]

Gets a string representation of the IP and port in use.

Definition at line 275 of file Socket.cs.

bool Sylloge.Net.Socket.IsClosing [get, set]

Gets if the current sockets are closing.

Definition at line 148 of file Socket.cs.

bool Sylloge.Net.Socket.IsConnected [get, set]

Gets if the socket is connected.

Definition at line 152 of file Socket.cs.

bool Sylloge.Net.Socket.IsLocalHost [get, set]

Gets if the socket/connection is the local host.

Definition at line 156 of file Socket.cs.

bool Sylloge.Net.Socket.IsRunning [get, set]

Gets if thread is running.

Definition at line 164 of file Socket.cs.

System.IAsyncResult Sylloge.Net.Socket.m_AsyncResult [get, set, protected]

The async result of the socket communcation operation.

Definition at line 127 of file Socket.cs.

System.Windows.Forms.Timer Sylloge.Net.Socket.m_KeepAlive [get, set, protected]

A keep alive timer that can be used to send custom keep alive messages.

Definition at line 131 of file Socket.cs.

KeepAliveType Sylloge.Net.Socket.m_KeepAliveType [get, set, protected]

The keep alive message type.

Definition at line 143 of file Socket.cs.

System.Threading.Thread Sylloge.Net.Socket.m_ListenThread [get, set, protected]

The listener thread for a client.

Definition at line 135 of file Socket.cs.

byte [] Sylloge.Net.Socket.m_Msg [get, set, protected]

The custom keep alive message if m_Type == CUSTOM.

Definition at line 139 of file Socket.cs.

int Sylloge.Net.Socket.Port [get, set]

Gets or sets the port used for the sockets.

Definition at line 168 of file Socket.cs.

System.Net.Sockets.NetworkStream Sylloge.Net.Socket.Stream [get, set]

The underlying stream used to read and write data.

Definition at line 176 of file Socket.cs.


Event Documentation

DelegateConnectionCloseError Sylloge.Net.Socket.ConnectionCloseError

Occurs when there is an error trying to close the connection.

Definition at line 91 of file Socket.cs.

DelegateDataReceived Sylloge.Net.Socket.DataReceived

Occurs when data is received on the listening socket.

Definition at line 71 of file Socket.cs.

DelegateSocketError Sylloge.Net.Socket.SocketError

Occurs when a internal socket error happens.

Definition at line 81 of file Socket.cs.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties Events