Jump to content
  • Advertisement
Sign in to follow this  

recv() gone haywire

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

Hello, I am currently at work on a primative IMer to play with the concepts of networking. However, I am having problems using the send() and recv() functions. Right now my server reads:
int currentClient=0;
cout<<"Client has connected"<<endl;
char recvdWords[36];
cout<<"Client says "<<recvdWords<<endl;

and my client reads:
cout<<"Connecting to server..."<<endl;
    //Define server socket
    sockaddr_in server;
    if(connect(serverSock,(struct sockaddr*)&server,sizeof(server))==SOCKET_ERROR)
          cout<<"\nError: Failed to connect to server!"<<endl;
          return 0;
    char words[]="Look! The program works!";

But when I run the client, the server spits out a string of strange characters. The string is the same every time, even if I change what I'm sending. Why won't send() and recv() work?

Share this post

Link to post
Share on other sites
There is a forum specifically for networking stuff.

At any rate, when you are getting errors it helps to check error codes. That would probably give you an idea of what the problem is. Likely recv is returning an error and since you're not checking for it you print more-or-less random garbage.

The most obvious problem is that you're recving from your listen socket instead of the socket returned by accept...

Share this post

Link to post
Share on other sites
Agreed -- you're calling recv() on the listenSock, when you should be passing the clients[currentClient] socket.

Moved to Networking and Multiplayer.

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!