Send Method (Byte[], Int32, Int32, SocketFlags)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Sends the specified number of bytes of data to a connected Socket, starting at the specified offset, and using the specified SocketFlags.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)

Syntax

'Declaration
Public Function Send ( _
    buffer As Byte(), _
    offset As Integer, _
    size As Integer, _
    socketFlags As SocketFlags _
) As Integer
public int Send(
    byte[] buffer,
    int offset,
    int size,
    SocketFlags socketFlags
)
public:
int Send(
    array<unsigned char>^ buffer, 
    int offset, 
    int size, 
    SocketFlags socketFlags
)
member Send : 
        buffer:byte[] * 
        offset:int * 
        size:int * 
        socketFlags:SocketFlags -> int 
public function Send(
    buffer : byte[], 
    offset : int, 
    size : int, 
    socketFlags : SocketFlags
) : int

Parameters

Return Value

Type: System. . :: . .Int32
The number of bytes sent to the Socket.

Remarks

Send synchronously sends data to the remote host specified in the Connect or Accept method and returns the number of bytes successfully sent. Send can be used for both connection-oriented and connectionless protocols.

In this overload, if you specify the DontRoute flag as the socketflags parameter, the data you are sending will not be routed.

If you are using a connectionless protocol, you must call Connect before calling this method or Send will throw a SocketException. If you are using a connection-oriented protocol, you must either use Connect to establish a remote host connection, or use Accept to accept an incoming connection.

If you are using a connectionless protocol and plan to send data to several different hosts, you should use SendTo. If you do not use SendTo, you will have to call Connect before each call to Send. It is okay to use SendTo even after you have established a default remote host with Connect. You can also change the default remote host prior to calling Send by making another call to Connect.

You must also be sure that the size does not exceed the maximum packet size of the underlying service provider. If it does, the datagram will not be sent and Send will throw a SocketException.

If you are using a connection-oriented protocol, Send will block until the requested number of bytes are sent, unless a time-out was set by using Socket..::..SendTimeout. If the time-out value was exceeded, the Send call will throw a SocketException. In nonblocking mode, Send may complete successfully even if it sends less than the number of bytes you request. It is your application's responsibility to keep track of the number of bytes sent and to retry the operation until the application sends the requested number of bytes. There is also no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the Send method means that the underlying system has had room to buffer your data for a network send.

Note

The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in nonblocking mode.

.NET Framework Security

See Also

Reference

Socket Class

Send Overload

System.Net.Sockets Namespace