AMPS C# Client  5.3.5.0
AMPS C# Client for .NET
AMPS.Client.TCPTransportImpl Class Reference

Socket implementation for TCPTransport. TCP Transport delegates to an instance of this class. This is used internally by the client's transport. There is usually no reason to make direct use of it. Its functionality is best accessed via the client instance. More...

+ Inheritance diagram for AMPS.Client.TCPTransportImpl:

Classes

class  TCPReaderThread
 

Public Member Functions

delegate void ExceptionListener (Exception e)
 
 TCPTransportImpl (Protocol messageType_, Properties properties_)
 Initializes a new instance of the TCPTransportImpl class with the specified message type and properties. More...
 
void setTransportFilter (TransportFilterModifiable filter_)
 Sets the transport filter for the TCP transport. More...
 
void setReadTimeout (int readTimeoutMillis_)
 Sets the read timeout for the TCP transport. More...
 
void setMessageHandler (MessageHandler h)
 Sets the message handler for the TCP transport. More...
 
void setDisconnectHandler (TransportDisconnectHandler h)
 Sets the disconnect handler for the TCP transport. More...
 
void setExceptionListener (ExceptionListener e)
 Sets the exception listener for the TCP transport. More...
 
void setThreadCreatedHandler (ThreadCreatedHandler handler)
 Sets the thread created handler for the TCP transport. More...
 
Action getIdleAction ()
 Gets the idle action for the TCP transport. More...
 
void setIdleAction (Action idleAction)
 
void connect (Uri addr)
 Establishes a connection to the specified address. More...
 
void disconnect ()
 Disconnects the TCP transport. More...
 
void send (MemoryStream buf)
 Sends the data contained in the provided memory stream over the socket. More...
 
Socket socket ()
 Returns the socket associated with this TCP transport. More...
 
long writeQueueSize ()
 Returns the size of the write queue. More...
 
long readQueueSize ()
 Returns the size of the read queue. More...
 
long flush ()
 Flushes any pending data in the TCP transport. More...
 
long flush (long timeout)
 Flushes any pending data in the TCP transport with a specified timeout. More...
 
virtual TCPTransport createTransport (Protocol messageType, TCPTransportImpl impl)
 Creates a new TCP transport based on the provided protocol and implementation. More...
 
virtual void handleCloseEvent (int failedVersion_, String message, Exception exception)
 Handles a close event, such as a disconnection or error, by invoking the appropriate disconnect handler. More...
 
void initFromClient (Client client)
 Initializes the transport configuration from the provided client. More...
 

Public Attributes

readonly object _lock = new object()
 
volatile int _connectionVersion = 0
 

Protected Member Functions

void broadcastException (Exception e)
 Broadcasts an exception to the exception listener if available. More...
 
virtual IPAddress resolveAddress (Uri addr)
 Resolves the IP address for the provided URI. More...
 
virtual void createSocket ()
 Creates a socket based on the resolved address. More...
 
virtual void createStream (Uri uri)
 Creates a stream for the provided URI and connects the socket. More...
 
virtual void connectSocket (Uri addr)
 Connects the socket to the specified URI. More...
 
void handshake ()
 Initiates the handshake process for the transport. More...
 
virtual void applySocketProperty (String propertyName, String propertyValue)
 Applies a socket property to self. Override this to add custom properties to your transport or intercept the stock ones. More...
 

Protected Attributes

Client _client = null
 
Uri _addr
 
IPAddress _resolvedAddr
 
Stream _socketStream = null
 
Socket _socket = null
 
bool _httpPreflight = false
 
bool _handshakeSetStream = false
 

Detailed Description

Socket implementation for TCPTransport. TCP Transport delegates to an instance of this class. This is used internally by the client's transport. There is usually no reason to make direct use of it. Its functionality is best accessed via the client instance.

Constructor & Destructor Documentation

◆ TCPTransportImpl()

AMPS.Client.TCPTransportImpl.TCPTransportImpl ( Protocol  messageType_,
Properties  properties_ 
)
inline

Initializes a new instance of the TCPTransportImpl class with the specified message type and properties.

Parameters
messageType_The message type for the transport.
properties_The properties for configuring the transport.

Member Function Documentation

◆ applySocketProperty()

virtual void AMPS.Client.TCPTransportImpl.applySocketProperty ( String  propertyName,
String  propertyValue 
)
inlineprotectedvirtual

Applies a socket property to self. Override this to add custom properties to your transport or intercept the stock ones.

Parameters
propertyNameThe property name from the URI.
propertyValueThe property value.

◆ broadcastException()

void AMPS.Client.TCPTransportImpl.broadcastException ( Exception  e)
inlineprotected

Broadcasts an exception to the exception listener if available.

Parameters
eThe exception to broadcast.

◆ connect()

void AMPS.Client.TCPTransportImpl.connect ( Uri  addr)
inline

Establishes a connection to the specified address.

Parameters
addrThe address to connect to.
Exceptions
AlreadyConnectedException
InvalidURIException
ConnectionRefusedException

◆ connectSocket()

virtual void AMPS.Client.TCPTransportImpl.connectSocket ( Uri  addr)
inlineprotectedvirtual

Connects the socket to the specified URI.

Parameters
addrThe URI to connect to.
Exceptions
SocketExceptionThrown when an error occurs while connecting the socket.

◆ createSocket()

virtual void AMPS.Client.TCPTransportImpl.createSocket ( )
inlineprotectedvirtual

Creates a socket based on the resolved address.

◆ createStream()

virtual void AMPS.Client.TCPTransportImpl.createStream ( Uri  uri)
inlineprotectedvirtual

Creates a stream for the provided URI and connects the socket.

Parameters
uriThe URI to create the stream for.

Reimplemented in AMPS.Client.TCPSTransportImpl.

◆ createTransport()

virtual TCPTransport AMPS.Client.TCPTransportImpl.createTransport ( Protocol  messageType,
TCPTransportImpl  impl 
)
inlinevirtual

Creates a new TCP transport based on the provided protocol and implementation.

Parameters
messageTypeThe protocol for the transport.
implThe implementation of the TCP transport.
Returns
A new TCP transport instance.

◆ disconnect()

void AMPS.Client.TCPTransportImpl.disconnect ( )
inline

Disconnects the TCP transport.

◆ flush() [1/2]

long AMPS.Client.TCPTransportImpl.flush ( )
inline

Flushes any pending data in the TCP transport.

Returns
Always returns 0.

◆ flush() [2/2]

long AMPS.Client.TCPTransportImpl.flush ( long  timeout)
inline

Flushes any pending data in the TCP transport with a specified timeout.

Parameters
timeoutThe timeout period.
Returns
Always returns 0.

◆ getIdleAction()

Action AMPS.Client.TCPTransportImpl.getIdleAction ( )
inline

Gets the idle action for the TCP transport.

Returns
The action to be performed during idle periods.

◆ handleCloseEvent()

virtual void AMPS.Client.TCPTransportImpl.handleCloseEvent ( int  failedVersion_,
String  message,
Exception  exception 
)
inlinevirtual

Handles a close event, such as a disconnection or error, by invoking the appropriate disconnect handler.

Parameters
failedVersion_The version of the failed connection.
messageThe error message.
exceptionThe exception that caused the disconnection.
Exceptions
DisconnectedExceptionThrown when a disconnect occurs.
RetryOperationExceptionThrown when a reconnect is attempted.

◆ handshake()

void AMPS.Client.TCPTransportImpl.handshake ( )
inlineprotected

Initiates the handshake process for the transport.

◆ initFromClient()

void AMPS.Client.TCPTransportImpl.initFromClient ( Client  client)
inline

Initializes the transport configuration from the provided client.

Parameters
clientThe client from which to initialize the transport configuration.

◆ readQueueSize()

long AMPS.Client.TCPTransportImpl.readQueueSize ( )
inline

Returns the size of the read queue.

Returns
The size of the read queue.

◆ resolveAddress()

virtual IPAddress AMPS.Client.TCPTransportImpl.resolveAddress ( Uri  addr)
inlineprotectedvirtual

Resolves the IP address for the provided URI.

Parameters
addrThe URI to resolve.
Returns
The resolved IP address.
Exceptions
InvalidURIExceptionThrown when the URI hostname cannot be resolved.

◆ send()

void AMPS.Client.TCPTransportImpl.send ( MemoryStream  buf)
inline

Sends the data contained in the provided memory stream over the socket.

Parameters
bufThe memory stream containing the data to send.
Exceptions
DisconnectedExceptionThrown when the socket is closed or encounters an error while sending the message.

◆ setDisconnectHandler()

void AMPS.Client.TCPTransportImpl.setDisconnectHandler ( TransportDisconnectHandler  h)
inline

Sets the disconnect handler for the TCP transport.

Parameters
hThe disconnect handler to set.

◆ setExceptionListener()

void AMPS.Client.TCPTransportImpl.setExceptionListener ( ExceptionListener  e)
inline

Sets the exception listener for the TCP transport.

Parameters
eThe exception listener to set.

◆ setIdleAction()

void AMPS.Client.TCPTransportImpl.setIdleAction ( Action  idleAction)
inline

Sets the idle action for the TCP transport.

Parameters
idleActionThe idle action to set.

◆ setMessageHandler()

void AMPS.Client.TCPTransportImpl.setMessageHandler ( MessageHandler  h)
inline

Sets the message handler for the TCP transport.

Parameters
hThe message handler to set.

◆ setReadTimeout()

void AMPS.Client.TCPTransportImpl.setReadTimeout ( int  readTimeoutMillis_)
inline

Sets the read timeout for the TCP transport.

Parameters
readTimeoutMillis_The read timeout in milliseconds.

◆ setThreadCreatedHandler()

void AMPS.Client.TCPTransportImpl.setThreadCreatedHandler ( ThreadCreatedHandler  handler)
inline

Sets the thread created handler for the TCP transport.

Parameters
handlerThe thread created handler to set.

◆ setTransportFilter()

void AMPS.Client.TCPTransportImpl.setTransportFilter ( TransportFilterModifiable  filter_)
inline

Sets the transport filter for the TCP transport.

Parameters
filter_The transport filter to set.

◆ socket()

Socket AMPS.Client.TCPTransportImpl.socket ( )
inline

Returns the socket associated with this TCP transport.

Returns
The socket associated with this TCP transport.

◆ writeQueueSize()

long AMPS.Client.TCPTransportImpl.writeQueueSize ( )
inline

Returns the size of the write queue.

Returns
The size of the write queue.

The documentation for this class was generated from the following file: