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

Author Topic: UDP packet occasionally not received correctly?  (Read 3689 times)

0 Members and 1 Guest are viewing this topic.

azurfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
UDP packet occasionally not received correctly?
« on: October 16, 2010, 08:49:18 am »
[SFML 2.0, rev 1582]

I set up two UDP sockets on localhost, and have one socket constantly send a packet containing '42' to the other (nonblocking) socket. Occasionally '0' will be received instead of '42'.

Am I doing something wrong?

Thank you.

Here is my code:

Code: [Select]

const int CLIENT_PORT = 2364;
const int SERVER_PORT = 2365;
sf::UdpSocket socketClient, socketServer;
socketClient.Bind(CLIENT_PORT);
socketClient.SetBlocking(false);
socketServer.Bind(SERVER_PORT);
sf::IpAddress theAddress("127.0.0.1");

while (true)
{
{
sf::Packet packet;
packet << 42;
socketServer.Send(packet, theAddress, CLIENT_PORT);
}

{
sf::Packet packet;
sf::IpAddress address;
unsigned short port;
if (socketClient.Receive(packet, address, port) == sf::UdpSocket::Done)
{
if (address == theAddress && port == SERVER_PORT)
{
int temp;
packet >> temp;
if (temp == 0)
{
printf("Value is 0\n");
}
}
}
}
}


[EDIT]
Some additional information: if I grab the size of the packet before trying to set temp, and then print it out when temp is not correct, these are some of the values I get:
131022,393050,65515,2227246,196525,982609,262032,7533309
Note that they all seem to roughly be multiples of the same number, 65515.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UDP packet occasionally not received correctly?
« Reply #1 on: October 16, 2010, 09:51:55 am »
Hi

You're not doing anything wrong, it looks like a bug. I'll fix it as soon as possible, thanks for your feedback :)
Laurent Gomila - SFML developer

azurfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
UDP packet occasionally not received correctly?
« Reply #2 on: October 16, 2010, 09:57:59 am »
No problem  :)

I added some additional information to my first post which may help.

Also, thanks for making such an awesome library. It is much nicer than SDL and others that I have used.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UDP packet occasionally not received correctly?
« Reply #3 on: October 16, 2010, 10:20:19 am »
Thanks for the additional information, but I already know what's wrong, it should be fixed soon :)
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
UDP packet occasionally not received correctly?
« Reply #4 on: October 16, 2010, 10:47:30 am »
Fixed.
Laurent Gomila - SFML developer

azurfire

  • Newbie
  • *
  • Posts: 6
    • View Profile
UDP packet occasionally not received correctly?
« Reply #5 on: October 16, 2010, 05:11:12 pm »
Great, thank you.  :)

 

anything