🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

connect() returning -1 but able to send()?

Started by
1 comment, last by belgare 22 years, 4 months ago
Hey guys here''s my delimma, I''ve created an MDI application in MFC for my client. I put all the socket stuff in my CView class because as I tried to set it up in CDocument, I noticed that CDocument doesn''t have a GetSafeHwnd function that I need for WSAAsyncSelect(), so I moved it over the CView. Well, when I connect, connect is returning -1, and my error is WSAEWOULDBLOCK, BUT, my server says my client has connected, and if i try sending data after the connect, it works and my server displays it (such as a simple text string). What''s going on? Cheers to any replies! PS Oh and even though send() is able to send data, because connect() is returning SOCKET_ERROR, well, my function i set up in WSAAsyncSelect() isn''t being called hehe.
Advertisement
OK, I don''t have the slightest clue of windoze programming, but here''s my take on the connect()-error:

The whole thing sounds like it should be this way. As I understand, CView is a manager for several CDocuments inside, so any blocking call in there could lock up the _whole_ mess, so it''s handled as an error. The fact that it connects anyway is strange, but try reading the documentation upside down or right to left (or both) and maybe you can find a valid explanation ;-)

Perhaps, it would just help to handle the WSAEWOULDBLOCK case separately as success or you try and export the whole sockets stuff to a completely different place.
Yeah, I''d prefer the socket stuff be elsewhere, preferably in the CDocument class, but how would i get an HWND to CDocument so I can set a message (using WSAAsyncSelect) up in CDocument message map to process events? (that make sense?) What I''m trying to do is make a chat client which is very similar to the way AL Client was made (found in resource section in mudconnector.com). I have a CRichEditCtrl in my CView class and if I can get the socket stuff in CDocument, I can send text to the CView class, but how do I get socket stuff to work in CDocument? I can''t do this in CDocument:

WSAAsyncSelect(sockfd, this->GetSafeHwnd(), WM_ONSOCKET, FD_READ | FD_CONNECT | FD_CLOSE);

because CDocument doesn''t have a GetSafeHwnd() function, so I don''t know how do map WM_ONSOCKET in CDocument message map. Please help?

This topic is closed to new replies.

Advertisement