Code:
. User A starts the application.
- Application creates a server service listening on port X.
- Application connects to a web server and:
> Obtains a list of waiting users.
> Registers User A as a waiting user.
- User A selects an opponent, User B, from the list of waiting users.
- Application starts the client service and:
> Connects to the server running on User B
> Sends a message telling User B to connect to User A. PROBLEM
BECAUSE A MAY NOT HAVE A GLOBALLY ADDRESSABLE IP
ADDRESS.
- At this moment User A and User B are officially connected and can
communicate with therespective client services.
It may not always be possible to get an ip address for the client machine. Suppose you're behind a router, which you probably are, and want to play a multiplayer game, then you likely have a local (internal) IP address (like 192.168.x.x) assigned to you by your router. The router is the one who has the external IP address. In this case if i wanted to connect directly to your computer, from my computer, i can only use the external IP address (the internal address is useless), and so i can only reach your router. Most routers are not set up to forward incoming requests onto the machines in the local network, let alone forward the correct port.
What this means is that it may not be possible for a client to connect to another client via IP addressing, hence there must always be a server in the middle. My plan is to use a server as a dispatcher.
With this approach, both clients, A and B, connect to the server. Then, since a client can't directly talk to the other client, whenever A wants to send a message to B it sends the message to the server and the server is the one who actually sends the message to client B.
This, i hope, won't really load the server up since it will only forward the messages, which involves minimum computation.
Any thoughts on this?