Re: help needed getting unique integer associated with socket
apm35@student.open.ac.uk wrote:
Lew wrote:
apm35@student.open.ac.uk wrote:
Pretty close is not good enough unfortunately.
That's all right. The hash code isn't generally unique anyway.
Well that confirms it. The hashCode is no good for my needs.
If you need a unique identifier, the Socket object itself may have to be the
identifier, since you cannot tolerate a reduction in the information set size.
Note that hash codes work just fine for Map and HashSet to uniquely locate any
key. The hash finds the bucket, and a List inside the bucket disambiguates.
Several clients could be running on different machines and still show the same
IP address to the server. Clients on the same machine can show different IP
addresses to the server also. So an IP address is not guaranteed to be unique
just like hash codes aren't.
I am hoping that a combination of client-side IP address and client-
side port number will be unique for each client.
At any given moment it might be, but you have no way of knowing if two
consecutive connections (or consecutive requests if using a stateless
protocol) via the same IP:port combination come from one client or different
ones. Also, some security software could mask the client port, making every
client behind it seem to come from the same port or from some obfuscated port
not correlated to the actual client.
If you control the network(s) involved and all the firewalls you can
compensate for these phenomena. If you are accepting connections from the
world you cannot solve these problems using IP address and port.
The canonical approach is for the server to create a unique token for the
client upon connection and have the client submit it with each request to
identify itself. Absence of a token indicates at least a new session, if not
a new client.
--
Lew