Connection Class |
public class Connection : Stream, IDisposable, IConnectionTimeouts
The Connection type exposes the following members.
| Name | Description | |
|---|---|---|
| Connection | Creates an instance of the Connection class with the specified binding. |
| Name | Description | |
|---|---|---|
| Available | 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. | |
| Binding | Get the Binding for this connection instance. | |
| BytesReceived | Gets the number of Bytes received for this Connection instance. | |
| BytesSent | Gets the number of Bytes sent for this Connection instance. | |
| CanRead |
Gets a value indicating whether the current connection supports reading.
(Overrides StreamCanRead) | |
| CanSeek |
Gets a value indicating whether the current connection supports seeking.
(Overrides StreamCanSeek) | |
| CanTimeout |
Gets a value that determines whether the current stream can time out.
(Inherited from Stream) | |
| CanWrite |
Gets a value indicating whether the current connection supports writing.
(Overrides StreamCanWrite) | |
| Connected | 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. | |
| DataSocketAvailable | Specified if the underlying DataSocket is Available. | |
| DataSocketConnected | Specified if the underlying DataSocket is connected. | |
| EnableNagle | Set the property value to true to enable the Nagle algorithm for send coalescing. | |
| Encoding | Get or set the encoding type for this connection instance. | |
| Length |
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) | |
| LocalEndPointAddress | 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. | |
| LocalEndPointPort | 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. | |
| MaxLineLength | 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). | |
| MaxLineLengthEnabled | 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. | |
| Position |
Get or set the position for the Connection instance.
(Overrides StreamPosition) | |
| ReadTimeout |
Gets or sets a value, in milliseconds, that determines how long the stream
will attempt to read before timing out.
(Inherited from Stream) | |
| RemoteEndPointAddress | 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. | |
| RemoteEndPointPort | 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. | |
| TimedOut | Gets the Timeout Status of this connection. | |
| Timeout | 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. | |
| TimeoutEnabled | 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. | |
| WriteTimeout |
Gets or sets a value, in milliseconds, that determines how long the stream
will attempt to write before timing out.
(Inherited from Stream) |
| Name | Description | |
|---|---|---|
| Abort | Aborts the Connection and closes the socket. | |
| BeginRead |
Begins an asynchronous read operation.
(Overrides StreamBeginRead(Byte, Int32, Int32, AsyncCallback, Object)) | |
| BeginWrite |
Begins an asynchronous write operation.
(Overrides StreamBeginWrite(Byte, Int32, Int32, AsyncCallback, Object)) | |
| BufferReadLine | Returns null if there is nothing in the buffer; Returns "" if it's an empty line, else the line in the buffer. | |
| Close |
Closes the data connection to the remote and terminates any calls to Receive that might still be blocking.
(Overrides StreamClose) | |
| Close(Boolean) | Closes the data connection to the remote and terminates any calls to Receive that might still be blocking with option to Dispose. | |
| Connect | Opens a connection to the target remote system using an IP address and port number. | |
| DataSocketClose | If data socket is connected, close it. | |
| DataSocketClose(Boolean) | If the Data Socket connection is open, shut it down and optionally close and dispose of it. | |
| DataSocketInitializeServerConnection | Initialize Server Connection Data Socket. | |
| DataSocketReceive | Receive the specified number of bytes from the Data Socket Connection. | |
| DataSocketReceiveWhatsAvailable | Receive as much data as is available from the Data Socket Connection. | |
| DataSocketSend(Byte) | Send data to the Data Socket Connection for the entire length of the buffer. | |
| DataSocketSend(Byte, Int32, Int32) | Send data to the Data Socket Connection until the specified size is reached. | |
| DataSocketSendAsMuchAsPossible | Send as much data as possible to the Data Socket Connection. | |
| Disconnect | Closes the data connection to the remote and terminates any calls to Receive that might still be blocking. | |
| Dispose | Disconnects and Disposes of the Connection elements. | |
| Dispose(Boolean) |
Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
(Inherited from Stream) | |
| EndRead |
End Reading the stream for this Connection instance
(Overrides StreamEndRead(IAsyncResult)) | |
| EndWrite |
Ends an asynchronous write operation.
(Overrides StreamEndWrite(IAsyncResult)) | |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
| Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) | |
| Flush |
Flush for the Connection.
(Overrides StreamFlush) | |
| GetHashCode | Serves as the default hash function. (Inherited from Object) | |
| GetType | Gets the Type of the current instance. (Inherited from Object) | |
| Initialize | Initialize this Connection instance's timeout and maxLineLength. | |
| InitializeServerConnection | Initializes the Server Connection for this instance. | |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) | |
| Read |
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)) | |
| ReadByte |
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) | |
| ReadLine | 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. | |
| Receive(Byte) | Receive reads bytes from the connection. This function can be blocked to wait for additional incoming data. | |
| Receive(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. | |
| ReceiveAllRemaining | Get data from connection until all bytes have been read (i.e., until Receive() returns 0). Uses a constant buffersize. | |
| ReceiveAllRemaining(Int32) | Get data from connection until all bytes have been read (i.e., until Receive() returns 0). Uses a buffersize passed as a parameter. | |
| ReceiveWhatsAvailable | 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. | |
| ResetStatistics | Reset the Statistics for this Connection instance. | |
| Seek |
Seek for Connection instance.
(Overrides StreamSeek(Int64, SeekOrigin)) | |
| Send(Byte) | This method sends a block of data to the remote side. | |
| Send(Byte, Int32, Int32) | This method sends a block of data to the remote side with specified Buffer, offset, and size. | |
| SetLength |
Sets the length for Connection instance.
(Overrides StreamSetLength(Int64)) | |
| SkipBytes | Skip the specified number of bytes to be read. | |
| StartTimeoutTimer | Start the Timeout Timer for this Connection instance. | |
| StopTimeoutTimer | Stop the Timeout Timer for this Connection instance. | |
| ToString |
ToString Method for this Connection instance.
(Overrides ObjectToString) | |
| TriggerOnBytesReceived | Trigger for OnBytesReceived. | |
| TriggerOnBytesSent | Trigger for OnBytesSent procedure. | |
| Write |
The Write method is provided for compatibility with the Stream base class; it behaves identically to Send.
(Overrides StreamWrite(Byte, Int32, Int32)) | |
| WriteByte |
Writes a byte to the current position in the stream and advances the position
within the stream by one byte.
(Inherited from Stream) | |
| WriteLine(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. | |
| WriteLine(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. | |
| WriteLineLF(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. | |
| WriteLineLF(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. |
| Name | Description | |
|---|---|---|
| OnBytesReceived | OnBytesReceived Event Handler for this Connection. | |
| OnBytesSent | OnBytesSent Event Handler for this Connection. |