Server Implementation Blocking-Socket Question - TCP-IP

This is a discussion on Server Implementation Blocking-Socket Question - TCP-IP ; Hi all, I am trying to implement a Game Server which will serve 0-5000 clients at a time. I am thinking to implement it in Python for to develop it faster. After days of reviewing different design approaches, I came ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Server Implementation Blocking-Socket Question

  1. Server Implementation Blocking-Socket Question

    Hi all,

    I am trying to implement a Game Server which will serve 0-5000 clients
    at a time. I am thinking to implement it in Python for to develop it
    faster.

    After days of reviewing different design approaches, I came up with
    the following:

    - Sockets are blocking, and we WILL have only one SOCKET connection to
    client.
    - Each client's request is processed in a separate thread.
    - When a client requests something, the request is put in the JobQueue
    of another thread. And this thread is responsible to process it.(This
    is a MUST, I do not want to rely on the client thread itself to
    process the Job)Here is my question arise.


    As we have only one connection to the client, it is possible to have
    THREAD A called socket.recv() and at the same time THREAD B called
    socket.send().

    Is it safe use send()/recv() simultaneously from different threads for
    the same socket. And please note that addiion to THREAD A and B there
    is a high chance that THREAD C might call socket.send() which makes
    multiple call to recv()/send()/send() on the same socket.

    Is multiple thread/one socket is not a reliable method for these
    situation, which IS? And, why?
    Different design suggestions?

    Thanks all.

  2. Re: Server Implementation Blocking-Socket Question

    In article
    ,
    k3xji wrote:

    > Hi all,
    >
    > I am trying to implement a Game Server which will serve 0-5000 clients
    > at a time. I am thinking to implement it in Python for to develop it
    > faster.
    >
    > After days of reviewing different design approaches, I came up with
    > the following:
    >
    > - Sockets are blocking, and we WILL have only one SOCKET connection to
    > client.
    > - Each client's request is processed in a separate thread.
    > - When a client requests something, the request is put in the JobQueue
    > of another thread. And this thread is responsible to process it.(This
    > is a MUST, I do not want to rely on the client thread itself to
    > process the Job)Here is my question arise.
    >
    >
    > As we have only one connection to the client, it is possible to have
    > THREAD A called socket.recv() and at the same time THREAD B called
    > socket.send().
    >
    > Is it safe use send()/recv() simultaneously from different threads for
    > the same socket. And please note that addiion to THREAD A and B there
    > is a high chance that THREAD C might call socket.send() which makes
    > multiple call to recv()/send()/send() on the same socket.


    It's definitely safe to call send() and recv() simultaneously. The two
    directions of a socket are totally independent, except that they get
    opened and closed together.

    Two threads both calling socket.send() concurrently might not be so
    safe, if this calls the underlying send() multiple times. This is
    because their send() calls might get interleaved. You'll need to use a
    mutex to serialize them.

    > Is multiple thread/one socket is not a reliable method for these
    > situation, which IS? And, why?
    > Different design suggestions?
    >
    > Thanks all.


    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE don't copy me on replies, I'll read them in the group ***

+ Reply to Thread