PDA

View Full Version : CL_UDPSocket crash when sending to unbound server



kurozael
03-19-2013, 04:33 PM
I'm experiencing issues whereby if I attempt to send a udp packet to an ip that isn't bound to accept it, my application will crash. I'm using CL_UDPSocket->send, how can I avoid this crash, and have it handled gracefully?

Thanks!

Judas
03-19-2013, 05:27 PM
Do you have a small example demonstrating this crash?

kurozael
03-19-2013, 05:45 PM
You should be able to reproduce this crash on Windows by simply binding a UDP socket with CL_UDPSocket->bind, and then attempting to use CL_UDPSocket->send to "localhost" but using a port that is not bound.

For example:

CL_UDPSocket* gSocket = new CL_UDPSocket;
gSocket->bind(CL_SocketName("7505"));
std::string data = "Some string";

gSocket->send(data.data(), data.length(), CL_SocketName("localhost", "8585")); //try send data to unbound port

Judas
03-19-2013, 08:15 PM
Just tried the following code with ClanLib 3.0 SVN:



using namespace clan;

SetupNetwork setup_network;

UDPSocket socket;
socket.bind(SocketName("5001"));
socket.send("foobarism", 9, SocketName("localhost", "5002"));

It did not cause any crash.

Are you catching any possible exceptions that could be thrown?

kurozael
03-20-2013, 07:36 PM
Just tried the following code with ClanLib 3.0 SVN:



using namespace clan;

SetupNetwork setup_network;

UDPSocket socket;
socket.bind(SocketName("5001"));
socket.send("foobarism", 9, SocketName("localhost", "5002"));

It did not cause any crash.

Are you catching any possible exceptions that could be thrown?

I'm using 2.3.7

Judas
03-21-2013, 06:33 AM
To my knowledge there aren't any differences between those two versions (except that one uses namespaces and the other uses the CL_ prefix.

Maybe you should try set a breakpoint at the line that crashes and then step into the function to see what is going wrong?