Telling the diffrence between two clients connected, from the same ip

I cant find away to do this, for example make it so when someone connects i want to make sure they dont open two connections to the same client so i made it so if two clients have two ip then dont accept the new client, but this means you have to be in diffrent houses to play the game. If say 20 people in an office or school all connected to the game under the same IP address how can i tell the clients apart?

You can’t. You can try, by grabbing something like the MAC address clientside, but that’s clientside security, which means it’s easily circumvented.

Any ideas what i can do diffrently then? To stop the server recving wrong data from clients, like if im running the client which is applet based and then open a new tab and open it up in that aswell and run it really messes the game up as im guessing servers reading data from client in new tab for client in first tab

Make each client select a unique name when they connect and append that name to every message. With that you can determine which client send the message and the client can decide if yes or not it should process the message it just received. You might have to send the message to more than one client (every socket with the same ip?).

A simple solution would be to assign a unique ID to a client when the socket connection is established with the server. That logic should be on the server side.

If you’re a sane person, you’re using TCP and you can simply ignore the IP all together. You’re dealing with InputStreams and OutputStreams, your application shouldn’t even look at the Socket after the initial code that grabs the streams from it. Abstract the network I/O away in your logic, until you’re solely dealing with ‘Player’ objects to identify which client sent/received data and how it should handle it, preferably using something like RMI.

don’t hold me to this because I may be telling you something completely false. but I would imagine that if you are binding the port, the second instance of the game would crash.

client side security :cranky:

I dont really understand what you mean, probably because i have no idea what RMI is, i kinda see what you mean. At the moment my server does just get a connection then starts a new thread with the socket passed in as argument gets the streams and it does I/O from that with logic in another thread and the I/O threads and logic threads just change static data in my other class which also displays some info.

It doesnt crash, it binds a diffrent port auto i think

you can try the game here
http://81.96.53.133/egg/WeaponHat.htm
Its fine aslong as you dont refresh the page or open two copys of it…
I like the idea of giving each client a random name and attaching it onto every packet, but okay the wrong listener on teh server gets data from a client its not supposed to be listening to, should i ignor it completely or try and pass it to the other thread or something :S

I can’t answer that question without knowing about your server architecture. But usually a client will send the message only once, so on the server side you must route it to the right listener because there won’t be another similar message coming from the client.

There is a difference between opening a port which is what a server does to listen for incoming connection and to connect to a port which is what a client does when it connect to a server. You can only open a port once, but you can connect to it many times. The port open by the server is just there to listen for new connection, when it detect one it create a new socket (on a completely different port if I’m right??) and it’s with that new socket that the server just created that you are now communicating.

But that just client-server theory…

EDIT : I should recheck the part about a different port… When you ask the client socket to which port it is connected I think it says the port you specified on the server.

Read the javadoc if you’re not too sure what you’re talking about.

yeah, that makes sense. wasnt 100% sure, was just a thought :).

Yes you can tell them apart by grabbing the remote port. The remote port is the outgoing port randomly opened by the client to connect to your server. This port should be different for every single computer that share a router.

You really shouldn’t use that as a way to identify a client. Create an object on the server and let of handle the streams. Then use that object to identify the client.

I don’t remember why but I recall trying to use the remote port and found out it was a bad idea, so I support Riven on that one.

Yes, of course your way is the way to go, since all Sockets are unique.

However, I’m just answering the OP’s question :slight_smile:

What happened?

Can’t remember :frowning: Sorry…

EDIT : Don’t think it was critical but just that it was not practical