sending messages to players on same lan network

Blitz3D Forums/Blitz3D Programming/sending messages to players on same lan network

CloseToPerfect(Posted 2009) [#1]
in udp is there a way to send directly to the local ip of a public ip.

for example if 3 players are in a game together,
1 is on the WWW.WAN and the other 2 are on a share LAN,
lets say host WWW ip is 96.54.123.13
player 2 and 3 share ip 88.33.122.75
player 2 has a local ip of 192.168.1.100
player 3 has a local ip of 192.168.1.101

can the host send to 192.128.1.101 via 88.33.122.75

i am storing the connect players in a type and i now have the server create a unique id for each player as they join. a private message is sent to player 192.128.1.101 all players on the LAN are polled for the unique id before showing the private message.

this works but i have some other issues with it that connecting straight to a local ip on a public ip would fix.

CTP


xlsior(Posted 2009) [#2]
If player 2 and player 3 actively *request* the information from player 1 -- in that case the routers NAT (Network Address Translation) will remember who the connection belongs to, and route the responses accordingly.

If player 1 is initiating the connection then it has no way of specifying that it wants to send to either player 2 and 3... Plus typically the router at player 2+3's LAN would be discarding the incoming packets anyway unless there's a service / port forward / DMZ set up that forwards the packets to either player 2 or 3, but not both.

Alternatively, if you are using a server / client approach instead of peer-to-peer, you can use a system where the clients can specify their own response ports upon joining the server. In that situation player 2 + 3 can each pick a different port which they can set up in their router to deliver to their respective computers.


CloseToPerfect(Posted 2009) [#3]
I have handle it this way for now.
I have a type for all players.
When a new player contacts the server the information from that client is stored including the the new players local ip sent with the contact info. server and client does a hand shake swapping info.
Server then sends the new player all the info for all the players including each players local ip that the server has stored.

Now since all players are using the same port everyone knows to portforward a specific port if they are behind a port.

so when a player want to message another player the port is opened and he sends the message including the destination local ip.

at the destination end the player receives a messages to his ip then checks the included local ip to verify it is for his machince and the message is processed.

Not all messages need to be verified like this, mainly when a new player joins the game/ or when a private message is sent from 1 player to another.

game data is sent to the host and and the host sends game data(positions and what not) to all other players to update.

I was going to handle messages to all players like game data but now since all players keep a updated list of all other players I have any player message all players directly. Saves some host load maybe.

perhaps the game data needs to be sent to all players from all players to? this would cut a middle man out and save off some milliseconds which would decrease some lag effects.

sorry doing some rambling in the thought process, need to go modify some code :)

CTP


xlsior(Posted 2009) [#4]
Well, bottom line is that the server won't be able to send out a message and have it arrive at two PC's on an internal LAN over the same port. You will only be able to set up a port forward in the router to a single LAN IP.

Actually, there may be another potential workaround:

- The server sees the incoming requests for clients to join the network
- If the server sees a 2nd request coming from the same IP as someone who already joined, it can deduce that that they are two users on the same LAN.
- when joining the server, have the computers also pass their local IP
- In case of duplicate, make sure that the first person connected is still there (no network hiccup causing a dupe, for example)
- If so, have the 1st PC act as a relay for the 2nd. Since you know the local LAN IP, you can send a notice to the first PC telling it to pass along info for PC #2 as well, and include the LAN IP of PC #2.

that way the server can still actively broadcast -- either directly, or indirectly through another players PC.


Mahan(Posted 2009) [#5]
Here is one technique I've tested myself and it worked on my router:

http://en.wikipedia.org/wiki/UDP_hole_punching

Just read the (short and concise) article on that link to see how it works, it's pretty simple for the application developer.

EDIT: Just to clarify - This worked without any port forwards or any of that stuff on the client side, and just required the clients to initiate a connection, against a "hole punching aware" server. Most game developers cannot rely on their customers to setup routers etc, to get their network game connecting. (+spelling)