Write Method

Write data to the socket with additional options.

Syntax

object.Write( Buffer, [Length], [Options], [RemoteAddress], [RemotePort] )

Remarks

The Write method sends the data in buffer to the socket. If the connection is buffered, as is typically the case, the data is copied to the send buffer and control immediately returns to the program. If the control is non-blocking and is out of buffer space, an error will be generated. If the control is blocking, the application will wait until the data can be sent.

The Buffer argument specifies the data that should be sent to the remote host. If this is a string or byte array, it may contain embedded null characters. It is possible to write data from an array of 16-bit or 32-bit integer values. In this case, the value of the ByteOrder property determines if those integers are converted from host to network byte order or not.

The Length argument specifies the maximum number of bytes to send to the server. Its maximum value is 231-1 = 2147483647. This argument is not required for string data. If a value is specified for this argument for other permissible types of data, and it is less than number of bytes that is determined by the control, then Length will override the internally-computed value. If the control is non-blocking and the send fails because it could not write all of the data to the server, the OnWrite event will be fired when the server can be written to again.

The Options argument is reserved for future functionality and should either be omitted, or specified with a value of zero. Specifying a non-zero value will cause the method to fail and return an error.

The RemoteAddress argument specifies the IP address of the remote host that the data will be sent to. For a TCP connection, it is recommended that this argument be omitted. If it is specified, the IP address must be the same value that was used to establish the connection. When writing data to a UDP socket, this is the IP address of the peer that will receive the datagram. This information can be used in conjunction with the Read method to send a datagram back to that host.

The RemotePort argument the port number on the remote host that the data will be sent to. For a TCP connection, it is recommended that this argument be omitted. If it is specified, the port number must be the same value that was used to establish the connection. When writing data on a UDP socket, this is the port number for the peer who will receive the datagram. This information can be used in conjunction with the Read method to send a datagram back to that host.

Return Value

This method returns the number of bytes actually written to the socket, or -1 if an error was encountered.

See Also

IsWritable Property, Timeout Property, Read Method, OnWrite Event


Copyright © 2008 Catalyst Development Corporation. All rights reserved.