DatagramSocket class

Expand
1 out of 1 rated this helpful - Rate this topic

DatagramSocket class

[This documentation is preliminary and is subject to change.]

Applies to: Metro style apps | desktop apps

Supports network communication using a UDP datagram socket.

Syntax


var datagramSocket = new Windows.Networking.Sockets.DatagramSocket();

Attributes

ActivatableAttribute(NTDDI_WIN8)
DualApiPartitionAttribute()
MarshalingBehaviorAttribute(Agile)
StaticAttribute(Windows.Networking.Sockets.IDatagramSocketStatics, NTDDI_WIN8)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)

Members

The DatagramSocket class has these types of members:

Constructors

The DatagramSocket class has these constructors.

ConstructorDescription
DatagramSocket Creates a new DatagramSocket object.

 

Events

The DatagramSocket class has these events.

EventDescription
MessageReceived An event that indicates that a message was received on the DatagramSocket object.

 

Methods

The DatagramSocket class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
BindEndpointAsync Starts a bind operation on a DatagramSocket to a local hostname and a local service name.
BindServiceNameAsync Starts a bind operation on a DatagramSocket to a local service name.
Close Closes the DatagramSocket object.
ConnectAsync(EndpointPair) Starts a connect operation on a DatagramSocket to a remote network destination specified as an EndpointPair object.
ConnectAsync(HostName, String) Starts a connect operation on a DatagramSocket to a remote destination specified by a remote hostname and a remote service name.
GetEndpointPairsAsync(HostName, String) Gets a list of EndpointPair objects based on a remote hostname and remote service name that can be used to send datagrams to a remote network destination.
GetEndpointPairsAsync(HostName, String, HostNameSortOptions) Gets a list of EndpointPair objects based on a remote hostname and remote service name and the sort order to be used.
GetOutputStreamAsync(EndpointPair) Starts an operation to get an IOutputStream to a remote network destination specified by an EndpointPair object that can then be used to send network data.
GetOutputStreamAsync(HostName, String) Starts an operation to get an IOutputStream to a remote destination specified by a remote hostname and a remote service name that can then be used to send network data.
JoinMulticastGroup Joins a DatagramSocket object to a multicast group.

 

Properties

The DatagramSocket class has these properties.

PropertyAccess typeDescription

Control

Read-onlyGets socket control data on a DatagramSocket object.

Information

Read-onlyGets socket information on the local and remote hostnames and local and remote service names for the DatagramSocket object.

OutputStream

Read-onlyGets the output stream to write to the remote host.

 

Remarks

To receive data using a DatagramSocket object, an app must assign the MessageReceived event to an event handler and then call either BindEndpointAsync or BindServiceNameAsync method to bind the DatagramSocket to a local service name or UDP port before calling the ConnectAsync method. If the event handler and bind operation happen after the connection operation, an error will occur.

The typical order of operations is as follows:

  • Create the DatagramSocket.
  • Use the Control property to retrieve a DatagramSocketControl object and set any advanced controls. This step is not normally needed by most apps.
  • Assign the MessageReceived event to an event handler.
  • Bind the DatagramSocket to a local service name or UDP port.
  • Call the ConnectAsync method to bind to remote endpoint. If the app wants to receive data from any remote endpoint on the DatagramSocket object, the ConnectAsync method should not be used since this binds the DatagramSocket to a specific remote endpoint. Instead the BindServiceNameAsync or BindEndpointAsync method should be used.

This class can also be used to join a multicast group and send UDP packets to the multicast group.

Requirements

Minimum supported client

Windows 8 Release Preview

Minimum supported server

Windows Server 2012

Namespace

Windows.Networking.Sockets
Windows::Networking::Sockets [C++]

Metadata

Windows.winmd

DLL

Windows.Networking.dll

Capabilities

internetClient
privateNetworkClientServer

See also

DatagramSocketControl
DatagramSocketInformation
DatagramSocketMessageReceivedEventArgs
How to use advanced socket controls
IClosable
Object
SetSocketMediaStreamingMode

 

 

Build date: 5/22/2012

Did you find this helpful?
(1500 characters remaining)
Community Additions ADD