Jump to content
  • Advertisement
Sign in to follow this  

Winsock2: Listen not working

This topic is 4458 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently building a Socket class in C++ which uses winsock 2. I started with simple initialize, connect and a listen functions which were working perfect. When I tried to make an asynchronous listen function it didn't work. I created a window and placed a WSAAsyncSelect() in the listen function, but the thing just wouldn't listen (literally). After that, my normal (blocking) listen function wouldn't work anymore either. I don't know why, because I had changed nothing in that part of the code. Even after removing all the things I added for the asynchronous listener it wouldn't work (I restored the old project with subversion). I even tried the example code from a tutorial which was working before but with no effect. The problem is that the listen function doesn't wait while it should. The windows firewall does ask me if I want to unblock the program but there is no listening connection popping up in netstat (there was before all of this). Does anyone know how to fix this? It's really hard to find anything on google since it doesn't give any error or something. For completeness, this is a part of the code:
	if (bind(m_socket, (LPSOCKADDR)&sockAddr, sizeof(sockAddr)) == SOCKET_ERROR)

	listen(m_socket, 1)
If I replace those lines with this one it does connect properly:
	if (connect(m_socket, (LPSOCKADDR)&sockAddr, sizeof(sockAddr)) == SOCKET_ERROR)
		return false;

Share this post

Link to post
Share on other sites
Hmm okay. I'll try it and hope it works.

I'm wondering why it did work this way before though.

Wooow it's working :D. Thanks a lot.

But still, I was very very certain that I didn't include an accept() before. Weird..

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!