SFML community forums
Help => Network => Topic started by: D on January 17, 2011, 05:15:49 pm
-
Hi. I'm using SFML2 in my project and non-blocking UDP socket. According to the API (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Socket.htm#a51bf0fd51057b98a10fbb866246176dc), I should get enum code 1 (NotReady), when I send data when the previous data hasn't been completely sent yet, do I understand this correctly?
When I run the code (just sending data in a loop), on OS X, I get enum code 3 (Error) when the previous data hasn't been sent yet. On Windows, I get 0 (Done) all the time. Either there's a bug in the library, or I'm just understanding the whole thing wrong. Receiving works correctly afaik.
-
Can you show a complete and minimal piece of code that reproduces this problem?
-
The following code:
#include <SFML/Network.hpp>
#include <iostream>
int main() {
sf::IpAddress ip("localhost");
sf::UdpSocket socket;
sf::Packet packet;
sf::Socket::Status socket_status = sf::Socket::Done;
sf::Socket::Status receive_status = sf::Socket::Done;
unsigned short port = 55555;
socket.Bind(sf::UdpSocket::Socket::AnyPort);
socket.SetBlocking(false);
while (true) {
socket_status = socket.Send(packet, ip, port);
if (receive_status==0) {
receive_status = socket.Receive(packet,ip,port);
std::cout << "Received." << std::endl;
}
std::cout << "Socket status is: " << socket_status << std::endl;
std::cout << "Receive status is: " << receive_status << std::endl;
if (!socket_status==0)
return 1;
packet.Clear();
}
}
Produces following output (on Mac OS X 10.6.6):
Socket status is: 0
Receive status is: 1
Socket status is: 3
Receive status is: 1
Strangely, I found out that if I comment out the receive part (even if it is not called even once), both statuses are always 0. I don't know how what output Windows does, because I don't have a Windows computer around, but I'll post it too later on, if needed. I didn't have any server running when doing this test, but it shouldn't affect the outcome, should it?
Is this a bug or is it my code? :) Thanks for your help.
-
Ok I'll test that, thanks for the code. I'll try it on Linux, the network code is the same as on Mac OS X.
-
Any news regarding to the issue?
-
Not yet, sorry. There are so many things that I have to test... :cry: