Sign in to follow this  

Packet loss in 1server&multipleClients model

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

Hi,

By using winsock I am building a networked application :

1) My each client has 1 thread to process `SendToServer` message queue and another thread to receive and push to a received messages queue.

So with n clients , I have 2n threads

2) My server has 1 connection-acceptor thread , 1 toSend message queue processor
and have multiple threads per client to receive from clients.

So with 1 server , I have n+2 threads

The problem is :


When I build a test application , when sender sends packages to clients , all of them can
receive them succesfully ( server -> clients is ok , no packet loss )

But when clients send messages to one server , some of them are randomly lost.
(clients -> server is not ok)

Is this normal ? If not what should I change , thread numbers or what could you suggest ?
(Thread delays , or in other words changing miliseconds of sleep calls in thread runs do not change anything )

Share this post


Link to post
Share on other sites

While it may not be directly related to your question, you may want to consider the approach to your server, depending on the load you expect the server to handle.

More specifically and generally, a server should never allocate a separate thread for each client connection. In a high client connection scenario, you will find that your server will eventually reach a point where performance becomes a big issue due to thread-per-client approach.

What you should look into is using select() or IOCP if you're programming on Windows in order to minimize the number of server-side threads. In an IOCP example, a single server thread manages a large number of client connections simultaneously by utilizing a worker thread pool concept.

You can also look into boost::asio library too.

I'd suggest you look into this sooner rather than later as the approach one takes with their server and client connection support can affect how you inevitably code the remainder of your server.

Share this post


Link to post
Share on other sites
BTW I fixed my code , in my test code , I didnt give enough time to establish connections between server and the clients , after adding some more code it is ok now.

Thanks for suggestions. For a thread pool implementation , I`d like to ask
if there is any suitable design pattern for implemetation ?

Share this post


Link to post
Share on other sites
I suggest you re-write your server as a single-threaded application using select().

Also, if you're using TCP, you have to frame each packet with a length prefix (just as if you were reading data from a file).

More hints can be found in the Forum FAQ.

Share this post


Link to post
Share on other sites

This topic is 2590 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this