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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Vaclav

Pages: [1]
1
Network / How to read an sf::Packet twice
« on: September 06, 2013, 03:36:00 pm »
Hey,
I want to read an sf::Packet instance two times. I do not want to copy it and read the other instance for the second time.
I looked at the API: http://sfml-dev.org/documentation/2.1/classsf_1_1Packet.php
And I didn't find anything like rewind. So this isn't possible, is it?
If I try to read it when I reached the packet's end, it goes to an error state, and doesn't rewind, does it?

2
Network / Re: Time duration of udp_socket.send(...)
« on: September 04, 2013, 01:19:53 pm »
Thank you Laurent.
You're right, only the first call takes longer.

3
Network / Time duration of udp_socket.send(...)
« on: September 04, 2013, 11:35:28 am »
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.

Pages: [1]
anything