Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Socket.Send Method (Generic IList, SocketFlags, SocketError)

Note: This method is new in the .NET Framework version 2.0.

Sends the set of buffers in the list to a connected Socket, using the specified SocketFlags.

This method is not CLS-compliant.  The CLS-compliant alternative is Send(Byte[],Int32,SocketFlags).

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

[CLSCompliantAttribute(false)] 
public int Send (
	IList<ArraySegment<byte>> buffers,
	SocketFlags socketFlags,
	out SocketError errorCode
)
/** @attribute CLSCompliantAttribute(false) */ 
public int Send (
	IList<ArraySegment<byte>> buffers, 
	SocketFlags socketFlags, 
	/** @attribute OutAttribute() */ /** @ref */ SocketError errorCode
)
JScript does not support passing value-type arguments by reference.

Parameters

buffers

A list of ArraySegments of type Byte that contains the data to be sent.

socketFlags

A bitwise combination of the SocketFlags values.

errorCode

A SocketError object that stores the socket error.

Return Value

The number of bytes sent to the Socket.

Exception typeCondition

ArgumentNullException

buffers is a null reference (Nothing in Visual Basic).

ArgumentException

buffers is empty.

SocketException

An error occurred when attempting to access the socket. See the Remarks section for more information.

ObjectDisposedException

The Socket has been closed.

This overload requires at least one buffer that contains the data you want to send. The SocketFlags value defaults to 0. 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 the SendTo method. If you do not use the SendTo method, you will have to call Connect before each call to Send. You can 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.

If you are using a connection-oriented protocol, Send will block until all of the bytes in the buffer 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 non-blocking mode, Send may complete successfully even if it sends less than the number of bytes in the buffer. 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 bytes in the buffer. 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.

NoteNote

If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.

NoteNote

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.

NoteNote

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft