IP Communication
194
NetLinx Programming Language Reference Guide
When the message is received at 192.168.0.1, the message will be delivered to the DATA_EVENT for
dvUDPServer and the IP address UDP/IP port of the sender of the message will be available in the
DATA.SOURCEIP and DATA.SOURCEPORT variables. A UDP (2) socket would be used in this case to
send a response to the client. Since we will no longer need to listen after sending the response, since
there would be no response to the response, we would open the socket using the following:
IP_CLIENT_OPEN(dvUDPClient,DATA.SOURCEIP,DATA.SOURCEPORT,IP_UDP)
Note that UDP with Receive (3) is only available when calling IP_CLIENT_OPEN.
Multicast
NetLinx can send and receive multi-cast UDP messages. To send a multi-cast UDP message, all you
need to do is specify a multi-cast address and port in the
IP_CLIENT_OPEN function such as the
following:
IP_CLIENT_OPEN (dvIPClient.Port,'239.255.255.250',1900,IP_UDP)
To receive multi-cast UDP messages, you must call the IP_MC_SERVER_OPEN function:
IP_MC_SERVER_OPEN (dvIPServer,'239.255.255.250',1900)
The NetLinx master will join the multi-cast session and allow you to receive and transmit UDP multi-
cast messages.
Example IP Code
PROGRAM_NAME='IPExample'
(***********************************************************)
(* DEVICE NUMBER DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_DEVICE
dvIPServer = 0:2:0
dvIPClient = 0:3:0
(***********************************************************)
(* CONSTANT DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_CONSTANT
nIPPort = 8000
(***********************************************************)
(* VARIABLE DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_VARIABLE
IP_ADDRESS_STRUCT MyIPAddress (* .Flags *)
(* .HostName *)
(* .IPAddress *)
(* .SubnetMask *)
(* .Gateway *)
(***********************************************************)
(* STARTUP CODE GOES BELOW *)
(***********************************************************)