Jump to content
  • Advertisement
Sign in to follow this  
TFS_Waldo

MFC Sockets (Chat App.) :: Socket class loses data when passed to another class?

This topic is 4855 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, everyone. I am working on a simple chat application that allows two people to chat back and forth. Now, I have a problem with this. The program has a server and a client. Whichever user wants to host the chat will run the server. The other user will input the other's IP address in and click "Connect". Well, that's not a problem. Those are the two main windows. Once a server is started, a separate dialog pops up, which is the chat window itself. Same goes for when the client makes a connection with the server. (BTW, they are two separate projects in the same workspace. =P) Each one includes a socket class, which I derived from 'CSocket.' The socket classes are member variables of the 'CServerDlg' and 'CClientDlg' classes, which are the two main windows. When a connection is started, and I send a message directly from the server (ex. "You connected! =)") it works just fine. But when I try to send a message after that, I get the error code '10038,' which is an operation on a non-socket. I have a function in the 'CChatDlg' class declared as 'SetSocket(CCliSocket sock);' and it sets the 'm_cliSock' member of the 'CChatDlg' class to the 'CCliSocket' passed to the 'SetSocket' function. Well, I think it is losing the socket data when I call 'SetSocket.' Can anyone offer any suggestions or anything of the sort? Thanks in advance! =)

Share this post


Link to post
Share on other sites
Advertisement
Your SetSocket function should look like:

SomeDlg::SetSocket(CCliSocket& sock)
{
// Code
}


Passing it as reference will make sure the socket won't invalidate. Perhaps you should turn it into a pointer and turn the member variable of the dialog into a pointer aswell, so you only have 1 instance of the socket.

Toolmaker

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.

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!