IP Communication
193
NetLinx Programming Language Reference Guide
Receiving data
To receive data from a client, use a
DATA
event handler or a buffer created with
CREATE_BUFFER
or
CREATE_MULTI_BUFFER
. If an event handler is used, the data is located in the
Text
field of the
DATA
object. The syntax:
Data_Event[Device]
{
STRING:
{
// process incoming string (Data.Text)
}
}
Parameters:
Device
is (or contains as part of an array) the device representing the conversation
(0:LocalPort:0).
Sending data
To send data to the client, use the
SEND_STRING
command.
SEND_STRING 0:LocalPort:0, '<string>'
The device specification (0:LocalPort:0) is interpreted as follows:
Device Number: 0: The master
Port: LocalPort: The local port number
System: 0: This system (the client)
Receiving Data with UDP
Since UDP is connection-less, no formal agreement has been made between the client and server to
exchange data. The client simply sends a UDP message and hopes the server is listening. In many
protocols that use UDP for communication, there is an implied agreement for the client to receive date
from the server.
When a UDP client socket in created, the socket is assigned a UDP/IP port number, not to be confused
with local port. This UDP/IP port will be used to send UDP messages. The server, if listening, will
receive this message along with the IP address and UDP/IP of the client who sent the message.
Some UDP protocols have an implied agreement that the server will be able to respond to the client by
sending a response back to the IP address and UDP/IP from where the message originated. Although the
UDP protocol does not specify that the client must expect to receive messages in this way, many UDP/IP
require the client to listening for response after sending a message.
Netlinx has two UDP client implementations. These are UDP (2) and UDP With Receive (3). The first
implementation only sends message and cannot receive messages. UDP with Receive will send and
receive messages on a single UDP/IP port.
It may seem like UDP (2) is not needed; however, it still serves and important purpose. Image you
wanted to send a UDP message and expect a response. The proper way to open this type of socket,
assuming you want to send a UDP message to 192.168.0.1 on UDP/IP port 6000, is:
IP_CLIENT_OPEN(dvUDPClient,'192.168.0.1',6000, IP_UDP_2WAY)
Now, if you were also writing the code for 192.168.0.1, you would need to have opened a UDP server
using the following:
IP_SERVER_OPEN(dvUDPServer,6000,IP_UDP)
Summary of Contents for NETLINX PROGRAMMING LANGUAGE
Page 15: ...Table of Contents xiii NetLinx Programming Language Reference Guide...
Page 16: ...xiv NetLinx Programming Language Reference Guide Table of Contents...
Page 18: ...Introduction 2 NetLinx Programming Language Reference Guide...
Page 76: ...Language Elements 60 NetLinx Programming Language Reference Guide...
Page 106: ...Combining Devices Levels and Channels 90 NetLinx Programming Language Reference Guide...
Page 112: ...Master To Master M2M 96 NetLinx Programming Language Reference Guide...
Page 182: ...Reserved Identifiers 166 NetLinx Programming Language Reference Guide...
Page 204: ...NetLinx UniCode Functions 188 NetLinx Programming Language Reference Guide...
Page 244: ...Appendix B Glossary 228 NetLinx Programming Language Reference Guide...
Page 245: ...Appendix B Glossary 229 NetLinx Programming Language Reference Guide...