Trouble with opening UDP socket via wxDatagramSocket

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
bimbarabam
In need of some credit
In need of some credit
Posts: 1
Joined: Tue Jan 29, 2019 3:59 pm

Trouble with opening UDP socket via wxDatagramSocket

Post by bimbarabam » Tue Jan 29, 2019 4:34 pm

Hello,
I have problem with receiving data from external device, which is connected to my PC via ethernet cable. It's part of bigger project, which I'm writing in MSVC using wxWidgets. Because of I chose this library some time ago, I thought it will be good to handle communication beetween computer and device with wxWidgets. The device is a LiDAR and it sends data via UDP to the computer. It's IP address is 192.168.1.200, and computer is 192.168.1.193. It was necessary to set proper PC IP address and set subnet mask to 255.255.255.0 to establish connection between these two devices. Device send UDP on port 6699. I tried to see some data with some prepared by producer app, to see that i did network configuration properly. When i run this app as administrator i could see some preview (on normal user it was crash - weird). I can also see network traffic between this two IP addresses when I opened wireshark (but I still should open it via administrator at least at first time)
I need to save data from this LiDAR device with my own application. So I wrote simple and I can't even open socket OK and getLocal method are giving me errors. When try to replace Ok method with error app to obtain more information, app was throwing exception with message about violent reading.
I'm using widgets 3.0.2

Code: Select all

LiDARIPV4address.Hostname(wxT("192.168.1.200"));
LiDARIPV4address.Service(6699);
LiDARMSOPSocket = new wxDatagramSocket(LiDARIPV4address/);
	if (!LiDARMSOPSocket->IsOk())
	{
		wxMessageBox("error");
		//return;
	}
	else
	{
		wxMessageBox(" ok");
	}
	wxIPV4address  addrReal;
	if (!LiDARMSOPSocket->GetLocal(addrReal))
	{
		wxMessageBox("error");
	}
	else
	{
		wxMessageBox(wxString::Format(wxT("Server listen %s:%u \n"),
			addrReal.IPAddress(), addrReal.Service()));
	}
	

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3351
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Trouble with opening UDP socket via wxDatagramSocket

Post by ONEEYEMAN » Wed Jan 30, 2019 5:44 pm

Hi,
Basic questions:
1. Can you successfully ping you LIDAR device?
2. Can you successfully telnet to the device on the port in question?
3. Do you run any FW on the machine? Did you open the port for incoming traffic from the LIDAR IP?
4. Is the connection done thru the switch/router? Did it configured correctly (to pass UDP traffic, and not just TCP/IP one)?
5. It would be nice to have an exact error from the debugger in the first scenario.

At the same time nothing prevents you to use cURL to do the external communication over TCP/IP.
It is a free library and much more suited to do that task.

Thank you.

Ruro
Experienced Solver
Experienced Solver
Posts: 60
Joined: Wed May 23, 2007 2:20 pm
Location: Verona, Italy

Re: Trouble with opening UDP socket via wxDatagramSocket

Post by Ruro » Wed Feb 20, 2019 11:17 am

Hi,

when you open a socket in listening, the ip.address of the socket, is the pc one.
So the socket is locking on the right address for the incoming packet o the specified port.

Code: Select all

LiDARIPV4address.Hostname(wxT("192.168.1.193"));/*pc ip*/
LiDARIPV4address.Service(6699);
When you need to send the data to the device, you can use the wxDatagramSocket::SendTo(..);

Best Regards,
Nicola.

Post Reply