SocketTools .NET Edition

SocketWrench.WriteTo Method (String, String, Int32)

Write a string of characters to the socket.

[Visual Basic]
Overloads Public Function WriteTo( _
   ByVal buffer As String, _
   ByVal hostAddress As String, _
   ByVal hostPort As Integer _
) As Integer
[C#]
public int WriteTo(
   string buffer,
   string hostAddress,
   int hostPort
);

Parameters

buffer
A string that contains the data to be written to the socket.
hostAddress
A string value which specifies the address of the remote host that the data will be sent to. For datagram sockets, this may be any valid Internet address. For stream sockets, this must be the same address that was used to establish the connection.
hostPort
An integer value which specifies the port number of the remote host that the data will be sent to. For datagram sockets, this may be any valid port number. For stream sockets, this must be the same port number that was used to establish the connection.

Return Value

An integer value which specifies the number of bytes actually written to the socket. If an error occurs, a value of -1 is returned and the application should check the value of the LastError property to determine the cause of the failure.

Remarks

The WriteTo method sends a string of characters to the remote host. If there is enough room in the socket's internal send buffer to accommodate all of the data, it is copied to the send buffer and control immediately returns to the caller. If amount of data exceeds the available buffer space and the socket is in blocking mode, then the method will block until the data can be sent. If the socket is in non-blocking mode and the send buffer is full, an error will occur.

This method is typically used when writing text data to a datagram socket.

See Also

SocketWrench Class | SocketTools Namespace | SocketWrench.WriteTo Overload List