SFML community forums

Help => Network => Topic started by: texus on August 13, 2011, 08:29:04 pm

Title: SocketUDP.Receive returns Error when sending delete
Post by: texus on August 13, 2011, 08:29:04 pm
I was using the SocketUDP while I noticed something strange.
When I use
Code: [Select]
SocketUDP.Send("delete", 7, IP_ADDRESS, 5000);
SocketUDP.Receive(ReceiveBuffer, BUFFER_SIZE, BytesReceived, IP_Address, Port);
then the last line returns sf::Socket::Error.
The return value of the first line is always Done.

If I change "delete" into any other word then it returns Done, but when it starts with delete then it fails (even "delete_test" fails).

This happens with both blocking and non-blocking. (Of course in non-blocking there has to be a sleep between the lines.)
Is there some reason why you can't send "delete"?

PS: I am using SFML 1.6.
Title: SocketUDP.Receive returns Error when sending delete
Post by: Laurent on August 13, 2011, 08:44:16 pm
No :shock:

I've tried with the Sockets example and SFML 2, I can send "delete" without problem.
Title: SocketUDP.Receive returns Error when sending delete
Post by: texus on August 14, 2011, 12:33:54 pm
It was indeed stupid to assume that the fault was with sending delete.
When I sent "delete" then the server gave my a different answer than when I sent something else.
The only difference was that the text I received was a few characters longer.

After searching for a while I finally found my mistake: I had defined BUFFER_SIZE as 25 instead of 256.

Thanks for your time and sorry for starting this useless topic.
Title: SocketUDP.Receive returns Error when sending delete
Post by: Nexus on August 14, 2011, 03:23:41 pm
You could use a std::vector<char> or std::array<char, size> as buffer, then you always have the correct size without needing additional constants.

Code: [Select]
std::vector<char> buffer(256); // or
std::array<char, 256> buffer;

socket.Receive(&buffer[0], buffer.size(), ...);

By the way, nice nickname :D