Solved

Winsock send() stops working after a few uses

Posted on 2003-11-29
9
588 Views
Last Modified: 2010-04-07
Greetings,

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
Winsock/TCP

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.
Ericka
0
Comment
Question by:Ericka123
  • 5
  • 3
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9848596
Ericka, can you post the whole code ?
0
 

Author Comment

by:Ericka123
ID: 9850420
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 eschall@houston.rr.com.

Thanks
Ericka
0
 

Author Comment

by:Ericka123
ID: 9850642
Ughh....

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?
0
 

Author Comment

by:Ericka123
ID: 9865022
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
Ericka
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 45

Expert Comment

by:sunnycoder
ID: 9865083
I am sorry ... I have been keeping a bit busy lately ... I shall try to look into it and post back
0
 

Author Comment

by:Ericka123
ID: 9865090
***UPDATE***
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    
        Sleep(300);
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(); ?
0
 

Accepted Solution

by:
Ericka123 earned 0 total points
ID: 9865152
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.

Thanks

Thread Closed
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9865163
thats great ..
you can post in community support to get your points refunded

good luck
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now