Nathan
Nathan

Reputation: 672

Server-Client Model Issue

I have a TCP/IP Client and Server communicating with each other.

My Client is recving data from the server at an interval of 1 second viz. sleep(1000). My server does not have a sleep provision.

It works fine if i am recving a simple string like "hi" .

But if i dont introduce sleep in my server , my client seems to be in a hanged state or processes a hugh bulk of data at once at the launch.

Is my server too supposed to sleep too ?

Or can be an issue with processing of recved data?

Upvotes: 0

Views: 93

Answers (1)

AntonyM
AntonyM

Reputation: 1604

If your server is writing to the socket without a sleep then it will fill the TCP buffer on both sides very quickly, your client will then almost immediately have a load of data stuck in its local buffer to read. If you are looking to have the server be delayed by the sleep on your client then you can do it as a transaction instead where the server writes the string but then reads a byte. The client would then read the string and write one byte to signify that it had received it. This would keep the server in step with the client.

Upvotes: 1

Related Questions