Admin Production ni-theme
Current Publication

CreateUDPChannel

LabWindows/CVI

CreateUDPChannel

int CreateUDPChannel (unsigned int localPort, unsigned int *channel);

Purpose

Creates a UDP channel object that you can use to send and/or receive UDP datagrams.

You must create a UDP channel object to send or receive any unicast, multicast, or broadcast messages. The new channel can receive messages sent only to the specified port number, though it can send messages to any port.

You must call DisposeUDPChannel to free resources when you finish using the channel.

Calling CreateUDPChannel is equivalent to calling CreateUDPChannelConfig with the following parameters:

CreateUDPChannelConfig (localport, UDP_ANY_ADDRESS, 1, NULL, NULL, channel)

Parameters

Input
Name Type Description
localPort unsigned int The local port number to open for UDP communication.

Applications must agree on the port number(s) to use for communication. According to the Internet Assigned Numbers Authority (IANA), do not use ports in the Well Known (0-1023) or Registered (1024-49151) ranges without IANA registration. Instead, use port numbers in the Dynamic/Private range: 49152-65535.

Note   Unless you need to listen on a specific port, NI recommends that you configure the UDP Support Library to select a free port by passing UDP_ANY_LOCAL_PORT for this parameter. If you need to specify a particular client port, be sure that it is available for use by your application to avoid conflicting with other TCP/UDP applications that may be using that port.
Output
Name Type Description
channel unsigned int A handle that uniquely identifies a UDP channel object.

Return Value

Name Type Description
status int Return value indicating whether the function was successful.

Zero indicates successful execution and a negative number indicates that an error occurred.

Call the GetUDPErrorString function to obtain a message that describes the error.

Additional Information

Library: UDP Support Library

Include file: udpsupp.h

LabWindows/CVI compatibility: LabWindows/CVI 8.5 and later

Examples

Refer to the following examples that use the CreateUDPChannel function:

  • udp\UDPChat.cws

    Open example
  • udp\UDPWriter.cws

    Open example