Winsock send() stops working after a few uses


It seems I have ran into another problem with my client/server application.

Some background on my problem.
Im using Visual Studios C++
All Console Apps

I have a client that connects to a server. Right now the client sends a object to the server and the server prints out the objects values to its screen. Object and its attributes:

struct Player
    char Name[15];
    char Msg[4096];

Example Message to server:
                       Ericka: I sent this message from the client.

Everything compiles and works nicely as its suppose to do. However after I send messages to the server 8 times, my server will no longer print out anymore messages. I have debugged the client and have verified that the PlayerObjs values are being updated before the client attempts to send the object.

Another strange thing is if I continue to try to send messages after the server stops printing them out on its console, the client stops printing out my message on the client console after the 16th attempt. If I close out the server application before the client application I get a

ERROR: Send failed...

message (on my client console) for each send attempt that didnt print out on the server side. I wrote the check for the ERROR message to let me know that a send was unsuccesful.

It looks to me that the send attempts are getting backlogged or something somehow and when I shutdown the server they then attempt to be sent to the server and I get a ERROR: Send failed message because it has lost connection. Why would the send()'s stop after only 8 times of sending data? This program is very small and simple so I dont see how the socket could be getting bottlenecked or something. Im very new to network programming. If anyone has any ideas on how to fix this I would be very grateful.

Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ericka, can you post the whole code ?
Ericka123Author Commented:
This problem has seemed to fix itself. The problem Im running into now is looking like my recv() call.

Everything works fine if its all running on one pc. If the client is running on the same pc as the server it send()s and recv()s fine. If a client is running on a seperate pc it recv()'s messages just fine, however if the client on the separate pc trys to send() a message then the server and all the clients gets jibberish that fills up the entire screen. It looks like its printing out the total size of the buffer and not just the used portion.

Im using ReadConsoleInput() to detect keypresses and ioctlsocket() for a non-blocking recv(). It wasnt doing all this until I tried to create a non-blocking recv() call with ioctlsocket() yesterday.

My code isnt extremely large but I do have it in separate .h and .cpp files for easier readability. I could post it but it would be a bit of a pain. Could I just email it to you? My email is

Ericka123Author Commented:

Im trying to duplicate the results of this. I find that if I run the server on my second pc with one client on the same pc as the server and one client on my first pc that I get the above mentioned results.

However if I run the server on my first pc with one client on the same pc as the server and a client on my second pc that everything works fine except that the client on the second pc gets total gibberish but the first with the server and a client work totally fine. The client running with the server gets all the sent messages that the second client sends along with the server.

I know none of that probally makes since hehe. Im starting to wonder if this might have something to do with me running multiple clients on my little home network? Im using 2WIRE, could this have something to do with it?

Wouldnt it give duplicate results if it had something to do with my coding?
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Ericka123Author Commented:
I fixed the above problem already. Well sorta. Now everything works 100% correctly if the clients are in debug mode. If they arent in debug mode it prints out the entire buffer and the data in the buffer is garbage.

I put breaking points right after the recv() calls on the client. As I "F5" through the breakpoints all the varibles are correct and it correctly prints the message out on the client. I have also noticed that the client that is running on the same pc as the server is working fine in or out of debug mode. Only clients on separate pc's seem to be having this problem.

Im hoping this is something very trivial and that someone might have ran into this before. Im going crazy with this please help.

So far I can put my experience of learning net programming in one sentence.
"Its been like breaking into Fort Knox with a dull spoon."  I am enjoying it though, just seems like a uphill battle for me hehe.

Anyways, Thanks in advance
I am sorry ... I have been keeping a bit busy lately ... I shall try to look into it and post back
Ericka123Author Commented:
Since I posted this I tried out a idea and thought maybe the debugger was stopping the program at the breakpoint so I put in    
and it jury rigged my problem. It is now printing out the message correctly instead garbage. Can anyone explain whats going on with this? Surely my pc isnt too fast. Why does it need to slow down while accepting the message from the server? And can someone explain how to achieve this same result without using Sleep(); ?
Ericka123Author Commented:
Hiya Sunny!

Sorry didnt see you before I made my last post. Its ok, I think I figured it out now.

I forgot that I used ioctlsocket(); when I was trying to figure out how I should make my socket not get blocked by recv() calls. As I was looking over my code I knoticed it and commented it out and the sleep() call and it seems to be working properly now. Hopefully its good to go finally.

I used FD_SET and select() on my client to see if the server had any data ready to be read so it wouldnt block my recv() call. I had just forgot to take the ioctlsocket out after I went that route instead.


Thread Closed

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thats great ..
you can post in community support to get your points refunded

good luck
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.