Sign in to follow this  

Winsock2: Listen not working

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this