C# Class Griffin.Net.Channels.TcpChannel

Represents a socket connection between two end points.

Important! Handle the ChannelFailed delegate to know why the channel failed.

Inheritance: ITcpChannel
Show file Open project: jgauffin/Griffin.Framework Class Usage Examples

Public Methods

Method Description
Assign ( Socket socket ) : void

Assign a socket to this channel

the channel will start receive new messages as soon as you've called assign.

You must have specified a MessageReceived delegate first.

Cleanup ( ) : void

Cleanup everything so that the channel can be reused.

Close ( ) : void

Signal channel to close.

Will wait for all data to be sent before closing.

CloseAsync ( ) : Task

Signal channel to close.

Will wait for all data to be sent before closing.

Send ( object message ) : void

Send a new message

Outbound messages are enqueued and sent in order.

You may enqueue byte[] arrays or Stream objects. They will not be serialized but MicroMessage framed directly.

TcpChannel ( IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder ) : System

Initializes a new instance of the TcpChannel class.

Private Methods

Method Description
CreateException ( SocketError socketError ) : Exception
HandleRemoteDisconnect ( SocketError socketError, Exception ex ) : void

Detected a disconnect

OnChannelFailure ( Exception exception ) : void

Detected a disconnect

OnMessageReceived ( object obj ) : void
OnReadCompleted ( object sender, SocketAsyncEventArgs e ) : void
OnSendCompleted ( object sender, SocketAsyncEventArgs e ) : void
ReadAsync ( ) : void

Method Details

Assign() public method

Assign a socket to this channel
the channel will start receive new messages as soon as you've called assign.

You must have specified a MessageReceived delegate first.

public Assign ( Socket socket ) : void
socket Socket Connected socket
return void

Cleanup() public method

Cleanup everything so that the channel can be reused.
public Cleanup ( ) : void
return void

Close() public method

Signal channel to close.

Will wait for all data to be sent before closing.

public Close ( ) : void
return void

CloseAsync() public method

Signal channel to close.

Will wait for all data to be sent before closing.

public CloseAsync ( ) : Task
return Task

Send() public method

Send a new message

Outbound messages are enqueued and sent in order.

You may enqueue byte[] arrays or Stream objects. They will not be serialized but MicroMessage framed directly.

public Send ( object message ) : void
message object Message to send
return void

TcpChannel() public method

Initializes a new instance of the TcpChannel class.
public TcpChannel ( IBufferSlice readBuffer, IMessageEncoder encoder, IMessageDecoder decoder ) : System
readBuffer IBufferSlice Buffer used for our reading.
encoder IMessageEncoder Used to encode messages before they are put in the MicroMessage body of outbound messages.
decoder IMessageDecoder /// Used to decode the body of incoming MicroMessages. The MessageReceived delegate will be /// overridden by this class. ///
return System