User`s guide
124
K
A
DAK
KwikNet Low Level Services
The UDP Channel
KwikNet offers an alternate, low level UDP API which you enable by editing your
Network Parameter File and checking the box labeled "UDP channel support" on the IPv4
property page (see Chapter 2.3).
KwikNet defines an abstraction called a UDP channel which can be used to control the
sending and receiving of UDP datagrams on the network. UDP datagrams cannot be sent
without first acquiring a UDP channel. Received UDP datagrams are rejected if an
associated UDP channel does not exist.
To send or receive UDP datagrams, you must first call KwikNet procedure kn_udpopen()
to open a UDP channel. In the call you must provide the IP address of the foreign host
with whom you wish to correspond. An IP address of 0.0.0.0 is used to indicate that you
will accept UDP datagrams from any foreign host. If you will only accept UDP
datagrams from a specific foreign host, you must also provide the protocol port number
for the foreign host. A foreign port number of 0 can be used to indicate that you will
accept a UDP datagram from any port at that foreign host.
The KwikNet procedure kn_udpopen() returns a handle which uniquely identifies the
UDP channel allocated by KwikNet for your use. This handle can be used in calls to
kn_udpsend() to send data through the UDP channel to any foreign host. However, you
will only be able to receive UDP datagrams from the foreign host identified when the
UDP channel was opened.
When you open the UDP channel, you can also bind the channel to a specific local IP
address and/or port. If you do provide an IP address but no port number, a port number
will be assigned for you. In this case, the foreign host will not be able to identify your
port until you send a datagram to the foreign host.
If you open the UDP channel with no local IP address or port specified, you will have to
send a datagram to the foreign host before it will be able to communicate with your local
host. Alternatively, you can use KwikNet procedure kn_udpbind() to bind your UDP
channel to a specific local IP address and port at some point after you have opened the
UDP channel but before you have sent any datagram to the foreign host. Having done so,
you can receive UDP datagrams on your UDP channel without first having to send a
UDP datagram to the foreign host to identify your IP address. Of course, that presumes
that the foreign host knows the IP address and port to which you are bound.
Once your application is finished conversing with the foreign host, it must call
KwikNet
procedure kn_udpclose() to close the UDP channel. The handle used to access the
UDP channel becomes invalid once the channel is closed.