Click or drag to resize

Connection Class

The Stream based Connection class is the basis for all communications between clients and servers. Clients can obtain a Connection object by calling one of the Connect methods of the Client component; Servers will obtain Connection objects for every incoming connection that gets established.
Inheritance Hierarchy
SystemObject
  Crestron.SimplSharp.CrestronIOStream
    Crestron.SimplSharp.NetConnection

Namespace: Crestron.SimplSharp.Net
Assembly: SimplSharpHelperInterface (in SimplSharpHelperInterface.dll) Version: 2.21.121
Syntax
C#
public class Connection : Stream, IDisposable, 
	IConnectionTimeouts

The Connection type exposes the following members.

Constructors
 NameDescription
Public methodConnection Creates an instance of the Connection class with the specified binding.
Top
Properties
 NameDescription
Public propertyAvailable Returns the number of bytes available in the local receive buffer. Override this method in descendant Connection classes if you need to perform additional handling or calculation on the size of available data.
Public propertyBinding Get the Binding for this connection instance.
Public propertyBytesReceived Gets the number of Bytes received for this Connection instance.
Public propertyBytesSent Gets the number of Bytes sent for this Connection instance.
Public propertyCanRead Gets a value indicating whether the current connection supports reading.
(Overrides StreamCanRead)
Public propertyCanSeek Gets a value indicating whether the current connection supports seeking.
(Overrides StreamCanSeek)
Public propertyCanTimeout Gets a value that determines whether the current stream can time out.
(Inherited from Stream)
Public propertyCanWrite Gets a value indicating whether the current connection supports writing.
(Overrides StreamCanWrite)
Public propertyConnected The boolean Connected property can be evaluated at any given time to find out if the Connection object is referring to an open Connection. When a connection is first obtained, it will be open and the property will be true. Once the connection has been closed, whether purposely or by remote, the property will turn to false.
Protected propertyDataSocketAvailable Specified if the underlying DataSocket is Available.
Public propertyDataSocketConnected Specified if the underlying DataSocket is connected.
Public propertyEnableNagle Set the property value to true to enable the Nagle algorithm for send coalescing.
Public propertyEncoding Get or set the encoding type for this connection instance.
Public propertyLength Length contains the entire known length of the incoming Connection stream. Returns the number of bytes that have been previously received (Position) plus the number of bytes that are waiting in the local receive buffer (Available).
(Overrides StreamLength)
Public propertyLocalEndPointAddress LocalEndPointAddress specifies the local address that this connection is assigned to. For clients, this will usually be a random IP address; For servers, this will be the IP address that the connection came in on.
Public propertyLocalEndPointPort LocalEndPointPort specifies the local port that this connection is assigned to. For clients, this will usually be a random port; For servers, this will be the port that the connection came in on.
Public propertyMaxLineLength The MaxLineLength property specifies the maximum number of bytes that a ReadLine operation will receive. The maximum line checking can be activated by the MaxLineLengthEnabled property, the default value is 1024 bytes (1kB).
Public propertyMaxLineLengthEnabled The MaxLineLengthEnabled property toggles whether the ReadLine function will enforce a maximum line length. When turned on (true), ReadLine will fail and the connection will be terminated if the remote side sends a line longer than the defined MaxLineLength bytes.
Public propertyPosition Get or set the position for the Connection instance.
(Overrides StreamPosition)
Public propertyReadTimeout Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.
(Inherited from Stream)
Public propertyRemoteEndPointAddress RemoteEndPointAddress specifies the remote address that this connection is assigned to. For clients, this will be the IP address that they connected to; For servers, this will usually be a random port of the connected client.
Public propertyRemoteEndPointPort RemoteEndPointPort specifies the remote port that this connection is assigned to. For clients, this will be the port that they connected to; For servers, this will usually be a random port on the connected client.
Public propertyTimedOut Gets the Timeout Status of this connection.
Public propertyTimeout The Timeout property specifies the maximum amount of time (in seconds) that a Connection will wait for incoming data within a single Receive operation. The timeout handling can be activated by the TimeoutEnabled property, the default value is 5 minutes.
Public propertyTimeoutEnabled The TimeoutEnabled property toggles whether the Connection will do automatic timeout checking. When turned on (true), the Connection will keep track of the time that passes during any single Receive operation - if a receive operation takes longer than the given timeout, the connection will be terminated.
Public propertyWriteTimeout Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.
(Inherited from Stream)
Top
Methods
 NameDescription
Public methodAbort Aborts the Connection and closes the socket.
Public methodBeginRead Begins an asynchronous read operation.
(Overrides StreamBeginRead(Byte, Int32, Int32, AsyncCallback, Object))
Public methodBeginWrite Begins an asynchronous write operation.
(Overrides StreamBeginWrite(Byte, Int32, Int32, AsyncCallback, Object))
Public methodBufferReadLine Returns null if there is nothing in the buffer; Returns "" if it's an empty line, else the line in the buffer.
Public methodClose Closes the data connection to the remote and terminates any calls to Receive that might still be blocking.
(Overrides StreamClose)
Public methodClose(Boolean) Closes the data connection to the remote and terminates any calls to Receive that might still be blocking with option to Dispose.
Public methodConnect Opens a connection to the target remote system using an IP address and port number.
Protected methodDataSocketClose If data socket is connected, close it.
Protected methodDataSocketClose(Boolean) If the Data Socket connection is open, shut it down and optionally close and dispose of it.
Protected methodDataSocketInitializeServerConnection Initialize Server Connection Data Socket.
Protected methodDataSocketReceive Receive the specified number of bytes from the Data Socket Connection.
Protected methodDataSocketReceiveWhatsAvailable Receive as much data as is available from the Data Socket Connection.
Protected methodDataSocketSend(Byte) Send data to the Data Socket Connection for the entire length of the buffer.
Protected methodDataSocketSend(Byte, Int32, Int32) Send data to the Data Socket Connection until the specified size is reached.
Protected methodDataSocketSendAsMuchAsPossible Send as much data as possible to the Data Socket Connection.
Public methodDisconnect Closes the data connection to the remote and terminates any calls to Receive that might still be blocking.
Public methodDispose Disconnects and Disposes of the Connection elements.
Protected methodDispose(Boolean) Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
(Inherited from Stream)
Public methodEndRead End Reading the stream for this Connection instance
(Overrides StreamEndRead(IAsyncResult))
Public methodEndWrite Ends an asynchronous write operation.
(Overrides StreamEndWrite(IAsyncResult))
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodFlush Flush for the Connection.
(Overrides StreamFlush)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodInitialize Initialize this Connection instance's timeout and maxLineLength.
Protected methodInitializeServerConnection Initializes the Server Connection for this instance.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodRead The Read method is provided for compatibility with the Stream base class; it behaves identically to Receive. It will block until the entire buffer is filled or the connection has been closed.
(Overrides StreamRead(Byte, Int32, Int32))
Public methodReadByte Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
(Inherited from Stream)
Public methodReadLine ReadLine will read data from the connection until a linebreak (either a CR LF or a single LF) is received. If MaxLineLengthEnabled is active, ReadLine will take security precautions to ensure the remote side is not sending strings that are too long.
Public methodReceive(Byte) Receive reads bytes from the connection. This function can be blocked to wait for additional incoming data.
Public methodReceive(Byte, Int32, Int32) Receive reads bytes from the connection with an offset and specified size. This function can be blocked to wait for additional incoming data.
Public methodReceiveAllRemaining Get data from connection until all bytes have been read (i.e., until Receive() returns 0). Uses a constant buffersize.
Public methodReceiveAllRemaining(Int32) Get data from connection until all bytes have been read (i.e., until Receive() returns 0). Uses a buffersize passed as a parameter.
Public methodReceiveWhatsAvailable ReceiveWhatsAvailable reads bytes from the connection to fill the passed byte[] buffer. Unlike Receive, this function will not block to wait for additional incoming data, but return immediately with the data that was available.
Public methodResetStatistics Reset the Statistics for this Connection instance.
Public methodSeek Seek for Connection instance.
(Overrides StreamSeek(Int64, SeekOrigin))
Public methodSend(Byte) This method sends a block of data to the remote side.
Public methodSend(Byte, Int32, Int32) This method sends a block of data to the remote side with specified Buffer, offset, and size.
Public methodSetLength Sets the length for Connection instance.
(Overrides StreamSetLength(Int64))
Public methodSkipBytes Skip the specified number of bytes to be read.
Protected methodStartTimeoutTimer Start the Timeout Timer for this Connection instance.
Protected methodStopTimeoutTimer Stop the Timeout Timer for this Connection instance.
Public methodToString ToString Method for this Connection instance.
(Overrides ObjectToString)
Protected methodTriggerOnBytesReceived Trigger for OnBytesReceived.
Protected methodTriggerOnBytesSent Trigger for OnBytesSent procedure.
Public methodWrite The Write method is provided for compatibility with the Stream base class; it behaves identically to Send.
(Overrides StreamWrite(Byte, Int32, Int32))
Public methodWriteByte Writes a byte to the current position in the stream and advances the position within the stream by one byte.
(Inherited from Stream)
Public methodWriteLine(String) The WriteLine method is similar to the Write method, but as in-parameter WriteLine it receives a string and finishes writing with carriage-return line feed character CRLF.
Public methodWriteLine(String, Object) The WriteLine method is similar to the Write method, but as in-parameter WriteLine it receives a string and finishes writing with carriage-return line feed character CRLF.
Public methodWriteLineLF(String) The WriteLineLF method is similar to the Write method, but as in-parameter WriteLineLF it receives a string and finishes writing with line feed character CRLF.
Public methodWriteLineLF(String, Object) The WriteLineLF method is similar to the Write method, but as in-parameter WriteLineLF it receives a string and finishes writing with line feed character CRLF.
Top
Events
 NameDescription
Public eventOnBytesReceived OnBytesReceived Event Handler for this Connection.
Public eventOnBytesSent OnBytesSent Event Handler for this Connection.
Top
Fields
 NameDescription
Public fieldCRLF CRLF byte array
Public fieldLF LF byte array
Top

Version Information

.NET

Supported in: 6.0

.NET Compact Framework

Supported in: 3.5
See Also