[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:
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.