Link to home
Start Free TrialLog in
Avatar of Engwi
Engwi

asked on

Client / Server question

Greertings

I have a delphi client (TIdTCPClient), that sends data to my server (TServerSocket). The data transmitted are a plain string with delimeted strings.

The client / server works fine, but at times it is a requirement that the client will really rapidly send data to the server ... With my testing it seems as if the data gets "lost".

For example, I transmit these strings, lets say, five different messages, directly after each other. When inspecting my database, I see that only two of them gets recorded. Should I, for testing purposes, perform a Sleep(500), between the transmitions of these strings, all is fine.

Any pointers will be appreciated.

Thanx in advance.
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

No, sleeps should not be required unless client nd server are ont the same system. Even then, I would use Sleep(0) instead of Sleep(500). Sleep(0) will just allow another thread to run it's cycle, thus if client and server are on the same system, the server thread would get a chance to read. If client and server are on different systems then it should not matter.
Maybe consider sending those multiple messages as one single, larger message...
Avatar of Engwi
Engwi

ASKER

Workskop Alex

Thanks, indeed, my client and server are on same machine {Testing purposes}, and I just confirmed your comment with Sleep(0), the transmission was more successfulle this time round, although not 100% effective. From your comment then I do take it that the "sleeps" would not be required at all if client and server on different machine ??

I will award the points on your reply.

Thanks again.  
ASKER CERTIFIED SOLUTION
Avatar of BlackTigerX
BlackTigerX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sleeps are useless if client and server are on different systems. It's also useless if you use a multi-processor PC, since the sleep is only needed to give another process a bit of breathing space. But if you have more than one processor (e.g. with two PC's) then both client and server have their own breathing space.
For testing purposes it would be better to use two computers. But it isn't always a requirement. But if the server is too busy, it could happen that your connection will time-out in which case the message gets dropped. It should be possible to detect this time-out, btw. And if you detect a time-out, just resend the message again. Be aware that since you're doing something with a database on the server, this database stuff will most likely slow things down. What I would do in such a case is make sure that every message sent to the server is handled by it's own thread. But I guess you're already doing this.