Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

belgare

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

This topic is 5987 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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!