Hello,
In my C++ game server, I used the socket number as the temporary ID of the connected player. Is there anyway to retrieve the socket number of a new player?
Atm, I am just using self.transport.getPeer().host, but this is only the IP address, not socket.
Thanks
Simon
_________________________________________________________________ The next generation of Hotmail is here! http://www.newhotmail.co.uk/
On Sun, 10 Jun 2007 11:26:19 +0100, Simon Pickles sipickles@hotmail.com wrote:
Hello,
In my C++ game server, I used the socket number as the temporary ID of the connected player. Is there anyway to retrieve the socket number of a new player?
Atm, I am just using self.transport.getPeer().host, but this is only the IP address, not socket.
Sockets may not have a file descriptor associated with them on all platforms. It's trivial maintain a counter yourself and assign a small unique integer to each client who connects. Why not do that, instead?
Jean-Paul
* Sunday 10 June 2007, alle 11:26, Simon Pickles scrive:
In my C++ game server, I used the socket number as the temporary ID of the connected player. Is there anyway to retrieve the socket number of a new player?
Atm, I am just using self.transport.getPeer().host, but this is only the IP address, not socket.
self.transport.getHandle().fileno()
.getHandle() returns a normal socket object from which you could get socket number.
Just for curiosity, are your players anonymous (e.g. not registered)?
On 6/10/07, Simon Pickles sipickles@hotmail.com wrote:
Hello,
In my C++ game server, I used the socket number as the temporary ID of the connected player. Is there anyway to retrieve the socket number of a new player?
Atm, I am just using self.transport.getPeer().host, but this is only the IP address, not socket.
If you only need this identifier for use in the implementation of the server, a much better way to identify players is by their Protocol object. On the other hand, if you do need to pass this identifier over the wire, then I agree with Jean-Paul that a small incremental or random number would be good.
On 6/10/07, Christopher Armstrong radix@twistedmatrix.com wrote:
If you only need this identifier for use in the implementation of the server, a much better way to identify players is by their Protocol object. On the other hand, if you do need to pass this identifier over the wire, then I agree with Jean-Paul that a small incremental or random number would be good.
This is what I do:
usersByID = {} # userID:user object idRange = range(1,1001) # Arbitrary limit...
def getNextUserID(): return list(set(idRange) - set(usersByID))[0]
When a user connects, I get the next available ID. If usersByID looks like:
{1:User1, 2:User2, 5:User5}
The next ID returned will be 3. I do this so I can keep reusing my IDs instead of infinitely incrementing them.