Simple UDP communication
scastagnoli
Posts: 3
Hi there.
I would send UDP packets from my Netlinx controller to a PC (with IP address 192.16.0.10).
My Netlinx source looks something like this in the DEFNE_START section:
IP_CLIENT_OPEN (12345, '192.16.0.10', 54321, 2) (*open the communication*)
instead the DEFINE_EVENT contains:
SEND_STRING 0:12345:0, 'UDP test!'
I cannot receive anything on my PC but I'm sure the listener is ok.
Could someone suggest me how to achieve this simple communication?
Thanks a lot in advance!
Stefano
I would send UDP packets from my Netlinx controller to a PC (with IP address 192.16.0.10).
My Netlinx source looks something like this in the DEFNE_START section:
IP_CLIENT_OPEN (12345, '192.16.0.10', 54321, 2) (*open the communication*)
instead the DEFINE_EVENT contains:
SEND_STRING 0:12345:0, 'UDP test!'
I cannot receive anything on my PC but I'm sure the listener is ok.
Could someone suggest me how to achieve this simple communication?
Thanks a lot in advance!
Stefano
0
Comments
Not Much to UDP.
// Little UDP Test Program, May help to explain UDP Communications
I've tried the following code:
PROGRAM_NAME='UDPTest'
DEFINE_DEVICE
SERIAL= 5001:1:0
dvSocket = 0:2:0
DEFINE_VARIABLE
LONG TL_ARRAY[] = {1000, 1000}
DEFINE_START
TIMELINE_CREATE (1, TL_ARRAY, 2, TIMELINE_RELATIVE, TIMELINE_REPEAT)
DEFINE_EVENT
DATA_EVENT [SERIAL]
{
ONLINE:
{
SEND_COMMAND DATA.DEVICE, 'SET BAUD 9600,N,8,1'
SEND_STRING SERIAL, 'Online'
}
}
TIMELINE_EVENT[1]
{
SWITCH(TIMELINE.SEQUENCE)
{
CASE 1: SEND_STRING SERIAL, 'Serial Test'
FOR (CONT=1; CONT<=10; CONT++)
{
OFF [Relay, 1]
WAIT 1
ON [Relay, 1]
}
IP_CLIENT_OPEN (dvSocket.Port, '192.16.0.10', 54321, IP_UDP) //IP address is 192.16.0.10 ;-)
SEND_STRING dvSocket, 'UDP test!'
IP_CLIENT_CLOSE(dvSocket.Port)
CASE 2: SEND_STRING SERIAL, 'Serial Test 2'
OFF [Relay, 1]
}
}
DEFINE_PROGRAM
but the listener still doesn't receive anything.
The listener is on port 54321 on the PC and the serial data is shown correctly on my PC using HyperTerminal.
Can you help me a little more?
CLIENT SAID: Hello, World!
SERVER SAID: GOT IT!
After some attempts I've made it works! Now I can receive packets from a PC and send to another using UDP protocol!
Thanks thanks thanks!