Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SocketUDP.Receive returns Error when sending delete  (Read 2910 times)

0 Members and 1 Guest are viewing this topic.

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
SocketUDP.Receive returns Error when sending delete
« 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.
TGUI: C++ SFML GUI

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SocketUDP.Receive returns Error when sending delete
« Reply #1 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.
Laurent Gomila - SFML developer

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
SocketUDP.Receive returns Error when sending delete
« Reply #2 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.
TGUI: C++ SFML GUI

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
SocketUDP.Receive returns Error when sending delete
« Reply #3 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
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything