I have a simple script that runs a server where one client can connect.
I would like to make it so that many clients can connect to one server
on the same port. Where can I find how to do this?
John wrote:[color=blue]
> I have a simple script that runs a server where one client can connect.
> I would like to make it so that many clients can connect to one server
> on the same port. Where can I find how to do this?[/color]
Then consider that "script that runs a server" could mean either you've
written a Python "script" that runs *as* a server, but has the
limitation of only one client connection at a time, or it could mean
that your script simply runs (via, for example, a call to os.system())
an external server program which has this limitation.
Given the ambiguity of your request, it's impossible to give a useful
answer without lots of guessing. Please clear up the above question and
provide much more detail and you'll likely get a more directly useful
response.
############### ############### ############### ############### ########
# set up a socket to listen for incoming connections from our clients
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
s.setsockopt(so cket.SOL_SOCKET , socket.SO_REUSE ADDR, 1)
s.bind((host, port))
s.listen(1)
John schrieb:[color=blue]
> I have a simple script that runs a server where one client can connect.
> I would like to make it so that many clients can connect to one server
> on the same port. Where can I find how to do this?
>
> Thanks,
> --j
>[/color]
use sockets.
the socket accept mehtoh returns a new socket (so now you hava one
"server socket" and a connection between to "client sockets" one used by
the requesting client and one created at the server side (retrund from
accept) ). you should start a new thread/process with this new socket
to handle the client request and use the "old" server socket again with
the accept method to wait for the next client to connect.
Robert Wierschke wrote:[color=blue]
> John schrieb:
>[color=green]
>> I have a simple script that runs a server where one client can connect.
>> I would like to make it so that many clients can connect to one server
>> on the same port. Where can I find how to do this?
>>
>> Thanks,
>> --j
>>[/color]
>
> use sockets.[/color]
Or, if you have no interest at all in the gory details and problems
of socket programming, have a look at Pyro (http://pyro.sourceforge.net).
Pyro lets you invoke remote python objects as if they were just regular
python objects.
Comment