Hello,
First I'd like to say SFML-Network is really neat and very easy to use, thank you for such a library.
Second I have some questions.
I'm sending an UDP packet and measuring how long it takes the function to return with an sf::Clock.
To my surprise, it takes quite long (around 4 ms) even if I set the socket non-blocking. Why is that, or can I do anything to reduce this, except for creating a thread myself? This seems quite a lot , suppose I want to send data to 15 clients over UDP, that's 60 ms already for one update, and the server also has to do physics, rendering at 60 fps and sending 10 updates per second.
To reduce the time, I have tried:
>setting the socket to blocking/non-blocking
>sending to local or public IP address (still 4 ms even for 127.0.0.1, and 2 ms for "localhost").
>receiving the packet with a client written in SFML (LOL I KNOW it doesn't matter for UDP)
>sleeping some time before sending
So any idea? What am I missing here?
My code:
#include <iostream>
#include <SFML/Network.hpp>
int main()
{
sf::UdpSocket socket;
socket.setBlocking(false);
sf::Clock clock;
sf::Time send_t;
char data[] = "hello";
sf::sleep(sf::milliseconds(1000));
clock.restart();
if (socket.send(data, 6, "127.0.0.1", 54000) != sf::Socket::Done) {
std::cout << "Error sending data.\n";
return -1;
}
send_t = clock.restart();
std::cout << "Send time: " << send_t.asMicroseconds() << "us\n";
return 0;
}
And I get:
Send time: 4250 us ( = 4.25 ms)
(in average, +/-200)
My system is: Windows XP SP3, but the hardware is newer than XP
(3 years old)
Another question:
When listening on more sockets, is there any difference or advantage between using blocking sockets and a socket selector, or checking non-blocking sockets in a loop manually?
I understand the tutorial supports the socket selector way, but it isn't a big difference, is it? Does it maybe depend on if you are using UDP or TCP?
Thank you for your help.