SFML community forums
Help => Network => Topic started by: retep998 on January 18, 2011, 07:05:53 pm
-
I have the following code:
sf::TcpListener listener;
if (listener.Listen(30273) != sf::Socket::Done) {
std::cout << "WE FAILED AT LISTENING! FUUUUUUUUUUUUUUUUUU!" << endl;
}
And I get the following error messages:
Failed to set socket option "TCP_NODELAY" ; all your TCP packets will be buffered
Failed to bind listener socket to port 30273
WE FAILED AT LISTENING! FUUUUUUUUUUUUUUUUUU!
I've tried all sorts of port numbers, and none of them worked.
I know they're open because I checked with netstat.
I'm on Windows 7 64 bit, behind a router that is port forwarded across every single port.
I have no firewalls.
I've never had issues with hosting servers.
I'm using the latest revision of sfml2, statically built.
I'm using Visual Studio 2010 Ultimate.
Any ideas?
-
Can you show a complete code? Have you tried the network example of the SFML SDK?
-
The examples run fine oddly enough.
//SFML Networking Library
#include <SFML/Network.hpp>
//Boost
#include <boost/thread.hpp>
void Listener() {
sf::TcpListener listener;
//We don't want our listener to block everything else
if (listener.Listen(30273) != sf::Socket::Done) {
std::cout << "WE FAILED AT LISTENING! FUUUUUUUUUUUUUUUUUU!" << endl;
}
}
boost::thread ListenThread(Listener);
int main() {
while(true){
//Other stuff which doesn't involve networking at all
}
}
I'm guessing it's probably running the listener stuff in a thread which is causing issues. I'll try running it in an sf::Thread and see if that fixes it. Otherwise it looks like I'll have to put the console stuff into a thread and leave the networking as the main part.
-
I'm guessing it's probably running the listener stuff in a thread
... and before main(). Man, when such errors happen, try to make your code more "normal" and see what makes it work ;)
-
I'm guessing it's probably running the listener stuff in a thread
... and before main(). Man, when such errors happen, try to make your code more "normal" and see what makes it work ;)
They're actually in separate files. But technically, it shouldn't make any difference... or does it? I'll try starting the thread from inside the main function.
And... it works!
You should add this to a FAQ of some sort.
If you're using threads NEVER start them directly in a file. Always start them from within a function.