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

Author Topic: TcpListener not working  (Read 4941 times)

0 Members and 2 Guests are viewing this topic.

retep998

  • Newbie
  • *
  • Posts: 17
    • View Profile
TcpListener not working
« on: January 18, 2011, 07:05:53 pm »
I have the following code:
Code: [Select]
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:
Code: [Select]
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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
TcpListener not working
« Reply #1 on: January 18, 2011, 08:20:28 pm »
Can you show a complete code? Have you tried the network example of the SFML SDK?
Laurent Gomila - SFML developer

retep998

  • Newbie
  • *
  • Posts: 17
    • View Profile
TcpListener not working
« Reply #2 on: January 18, 2011, 10:44:39 pm »
The examples run fine oddly enough.

Code: [Select]
//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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
TcpListener not working
« Reply #3 on: January 18, 2011, 11:06:53 pm »
Quote
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 ;)
Laurent Gomila - SFML developer

retep998

  • Newbie
  • *
  • Posts: 17
    • View Profile
TcpListener not working
« Reply #4 on: January 19, 2011, 01:43:56 am »
Quote from: "Laurent"
Quote
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.