UDP CONNECTION FAILS

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
3 posts • Page 1 of 1
riccardo.crociani
Posts:34
Joined: Tue Mar 31, 2015 12:52 pm

UDP CONNECTION FAILS

Post by riccardo.crociani »

I'm facing an error attempting to establish an UDP communication: I've opened an UDP port on a host (IP 172.31.192.167, port 7000) by Netcat command line process ("nc -vvv -u -l -p 7000").

Everything works ok if I try to send data by an other Netcat command line process ("nc -vvv -u 172.31.192.167 7000").

When I try to send data by Wincc OA it fails opening the socket. This is my code:

Code: Select all

main()
{
  dyn_errClass err;
  int sck;
  int res;
  
  string host = "172.31.192.167";
  unsigned port = 7000;
  
  sck = udpOpen(host, port);

  DebugN("sck",sck);
   
  if(sck>=0)
  {
    res = udpWrite(sck, "hello", host, port);
    DebugN("res",res);
    udpClose(sck);
  }

  err = getLastError(); 
  DebugN(err);
}
This is the output:
WCCOAui90:["sck"][-1]
WCCOAui90:[dyn_errClass 1 items
WCCOAui90:WCCOAui (90), 2016.12.29 09:48:49.822, CTRL, WARNING, 54, Unexpected state,
WCCOAui90: Module: _QuickTest_
WCCOAui90: Panel: C:\\Pvss\\UIClient.ct.311\\panels\\testVari.pnl []
WCCOAui90: Object: 564 named: "PUSH_BUTTON35" of type: PUSH_BUTTON
WCCOAui90: Script: Clicked
WCCOAui90: Line: 10, udpOpen, bind(172.31.192.167:7000): No error (0)
WCCOAui90:]


am I doing something wrong?

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: UDP CONNECTION FAILS

Post by mkoller »

Don't pass the port number 7000 to udpOpen - it would create a listening socket.
Instead, use port == 0

riccardo.crociani
Posts:34
Joined: Tue Mar 31, 2015 12:52 pm

Re: UDP CONNECTION FAILS

Post by riccardo.crociani »

Thanks Martin,
now it works :)

3 posts • Page 1 of 1