Hello,
It's the first time I use the networking part of SFML and I found out the class "Packet", which looks nice to send and receive data easily.
However, I never receive ANY data when I do something like:
TcpListener tcpListener;
TcpSocket mapControllerSocket;
tcpListener.setBlocking(false);
if (tcpListener.listen(MAP_CONTROLLER_COMMUNICATION_PORT) != Socket::Status::Done)
{
MessageBoxA(window.getSystemHandle(), "Cannot attach to Map Controller, check if port 40235 is not blocked or already in use.\r\n\r\nTerminating...", MAP_VIEWER_WINDOW_TITLE.c_str(), MB_ICONERROR);
return EXIT_FAILURE;
}
time_t startTime = time(NULL);
while (startTime + 10 >= time(NULL))
{
if (tcpListener.accept(mapControllerSocket) == Socket::Status::Done)
break;
}
if (mapControllerSocket.getRemoteAddress().toInteger() == 0)
{
MessageBoxA(window.getSystemHandle(), "Cannot attach to Map Controller, try to restart the program.\r\n\r\nTerminating...", MAP_VIEWER_WINDOW_TITLE.c_str(), MB_ICONERROR);
return EXIT_FAILURE;
}
Packet packet;
mapControllerSocket.receive(packet);
// Stuff...
It stays blocked (no exception, just waiting) at line mapControllerSocket.receive(packet);
However, when I replace the last 2 lines with:
byte *buffer = new byte[100];
size_t rcvLen = 0;
mapControllerSocket.receive(reinterpret_cast<void*>(buffer), 100, rcvLen);
It works fine! I receive my data as expected.
I'd really like to use the Packet class so... do you know what's the problem?