System.Net.Sockets.Socket.SendPacketsAsync Method

Sends a collection of files or in memory data buffers asynchronously to a connected System.Net.Sockets.Socket object.

Syntax

[System.MonoTODO("Not implemented")]
public bool SendPacketsAsync (SocketAsyncEventArgs e)

Parameters

e
The System.Net.Sockets.SocketAsyncEventArgs object to use for this asynchronous socket operation.

Returns

Returns true if the I/O operation is pending. The SocketAsyncEventArgs.Completed event on the e parameter will be raised upon completion of the operation.

Returns false if the I/O operation completed synchronously. In this case, The SocketAsyncEventArgs.Completed event on the e parameter will not be raised and the e object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation.

Remarks

The Socket.SendPacketsAsync(SocketAsyncEventArgs) method is used to send a collection of files or in memory data buffers to remote host. The System.Net.Sockets.Socket must already be connected to the remote host.

If a System.Net.Sockets.SendPacketsElement references a file in the working directory, it may be identified with just the name of the file; otherwise, the full path and name of the file must be specified. Wildcards and UNC share names are supported. If the file is not found, System.IO.FileNotFoundException is thrown.

To be notified of completion, you must create a callback method that implements the EventHandler<SocketAsyncEventArgs> delegate and attach the callback to the SocketAsyncEventArgs.Completed event.

The SocketAsyncEventArgs.SendPacketsFlags property on the e parameter provides the Window Sockets service provider with additional information about the file transfer. For more information about how to use this parameter, see System.Net.Sockets.TransmitFileOptions.

The following properties and events on the System.Net.Sockets.SocketAsyncEventArgs object are required to successfully call this method:

The caller may set the SocketAsyncEventArgs.UserToken property to any user state object desired before calling the Socket.SendPacketsAsync(SocketAsyncEventArgs) method, so that the information will be retrievable in the callback method. If the callback needs more information than a single object, a small class can be created to hold the other required state information as members.

This method uses the TransmitPackets function found in the Windows Sockets 2 API. For more information about the TransmitPackets function and its flags, see the Windows Sockets documentation in the MSDN Library.

Although intended for connection-oriented protocols, the Socket.SendPacketsAsync(SocketAsyncEventArgs) method also works for connectionless protocols, provided that you first call the erload:System.Net.Sockets.Socket.BeginConnect, erload:System.Net.Sockets.Socket.Connect, or Socket.ConnectAsync(SocketAsyncEventArgs) method to establish a default remote host. With connectionless protocols, you must also be sure that the size of your file does not exceed the maximum packet size of the underlying service provider. If it does, the datagram is not sent and Socket.SendPacketsAsync(SocketAsyncEventArgs) throws a System.Net.Sockets.SocketException exception.

The Socket.SendPacketsAsync(SocketAsyncEventArgs) method is optimized according to the operating system on which it is used. On Windows server editions, the Socket.SendPacketsAsync(SocketAsyncEventArgs) method is optimized for high performance.

On Windows client editions, the Socket.SendPacketsAsync(SocketAsyncEventArgs) method is optimized for minimum memory and resource utilization.

Use of the TransmitFileOptions.UseKernelApc flag in the SocketAsyncEventArgs.SendPacketsFlags property on the e parameter can deliver significant performance benefits. If the thread initiating the Socket.SendPacketsAsync(SocketAsyncEventArgs) method call is being used for heavy computations, it is possible, though unlikely, that APCs could be prevented from launching. Note that there is a difference between kernel and user-mode APCs. Kernel APCs launch when a thread is in a wait state. User-mode APCs launch when a thread is in an alertable wait state

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0