I want my next project to be played over the internet. Each session will require 2-8 players and one will host the session.
I was playing with the NET commands nethostgame etc... and it all works in Locally (127.0.0.1). But I want this over the Internet only.
Up to now there has been no way where I have been able to connect remotely to the server program run by another glbasic app.
If I have to play with the router stuff etc, then people would hate that when they get the game, lets face it no one wants to play with router settings to play an iPhone app.
I mean last iPhone app I got was only playable over the Internet and I never had to do any router changes etc...
Anyone can clarify this for me?
Thanks
The only way you'd have to modify a standard router's settings would be if you wanted to run a server on your own computer. That would mean opening a port so that incoming requests for connection can be replied to. As far as I know, unless you've got a very restricted router, outgoing TCP and UDP calls won't be a problem.
So the question is, where are you going to host the server? On that location, you'd have to set up ports correctly. The clients won't have a problem connecting.
Hey thanks for reply.
No I won't be hosting any game sessions, what I want to do is the following.
I want to allow for people to host their own sessions, eg you launch the game and you have 2 options:
1. Host or
2. Join
If you host then you need to give your friends the Internet ip address you have so they can connect remotely.
I'll restrict each session to 8 players including the host.
Other players will create their own sessions individually for their friends to join that one and so on.
Hope this is clear now, and hope this can be done or I'm sort of screwed with the idea I have in mind, which will be quite awesome :)
Thanks
Won't be a problem as long as the router settings are correct. This is a networking subject, it doesn't really matter if you code in C, C++, Java, GLBasic, whatever. I think most routers allow you to run a server as long as it's within a certain port range. Don't know the specifics, it's been a few years since I've had to concern myself with these things.
All in all, I don't think you're screwed. ;-) If I were you I'd find out which ports would be best to use. Maybe find out which ones get used by that game you described in the first post.
Thanks for reply.
Yes I'll try to search for ports and see if it works because the games I have, don't require you to do anything with router settings etc. Which is why I'm getting a bit confused as to why I need to check router stuff? I just don't get it :S
To circumvent router issues you would need to host server code yourself to add clients with ip:port who are hosting and others who want to join. Your server code could be php and mysql to keep track of rooms (games), their host and the clients for each room. The server would send the information of ip:ports connected to each room to the host until the game is finished and the room closed.
The host should be able to send direct to other devices like iphones on 3g. If the devices were on wifi to prevent router problems you would have to send commands to the server (you) and then each command sent redirected to all the users in the room.
No other way around it unless you ask each user to portforward their routers to their devices which again is problematic with dynamic ip's.
Server hosted code all the way for wifi I'm afraid, as I say 3G should be fine for direct ip to ip communication although not 100% you will have to do some tcp socket tests between 2 iphones that you have the ip of.
Visit http://ip.spicypixel.net to see if it gives you an ip on a 3G connection
BTW the http://ip.spicypixel.net is a permanent address that any GLB users can use within their code to get IP addresses for clients ;)
Thanks spicy.
So just what I thought, you need to run the server yourself. Then that would be overkill, as soon as you have a few too many people it will all stagger, for this you need a dedicated server.
I mean imagine game becoming popular, just 1000 people playing simultaneously will make the network collapse.
Thanks
It depends. The data sent/received/forwarded need only be packets of a few bytes so not necessarily too bad. However it could be perfect for a turn based game but not ideal for an arcade game where lag would come into play. 1Kb of data could serve a helluva lot of players if the packets of bytes were concise and lets face it 1Kb transfers isn't gonna strain a server anyway.
I guess it's not something you'd want to start and the work involved just to test it to find it fails. I want to do some server code at some point it's onto my todo list but as with coding generally my todo list is getting larger lol.
When we talk about the Internet nothing is guaranteed, latency drops of packets etc would constitute to many problems even with a handful of players.
Anyways one more thing I thought, even if I were to host the server myself where host and clients all have to share data with server then server reply to clients and the host. I think if any of the clients is running behind a router there could be problems here too, I'm come to the conclusion I'll stick to my offline games lol. I'm doing quite well with them to screw it up with something online.
Thanks spicy and rober, good luck to you both in your projects :booze:
I figured out a way to get around most routers. It's apparently called "UDP holepunching" or something like that. Ofcourse someone had thought of it before... :-)
I had it up on the community wiki that died a few years ago but here it is again. I think this is the latest version:
It's only a test to see if it works and it did :-)
The theory is: Most private gateways opens up a tunnel back in to recieve the answer if you send a packet out. It uses the same port and you used to send the packet. For most private gateways it doesn't matter to what IP you send the packet but to make it work on (almost) all private gateways you need to send the packet to the correct IP. This means the server needs to send a packet to all new clients before they can connect. Every client and server needs to keep sending heartbeats every few seconds to keep this tunnel open.
Ofcourse the user still needs to allow the software firewall to let your program send and recieve data on the network
What you need to do is set up a server where the clients negotiate for each others IP-adresses. Of course you can let them type in the ip-adress of the other side manually but to make it as easy as possible, you should make some sort of webserver that publishes all ip-adresses of all your clients. Won't take any bandwidth to speak about.
// --------------------------------- //
// Project: NetUDPThruRouter
// Start: Tuesday, September 15, 2009
// IDE Version: 7.104
// Moru
// Works if you send a message from inside the firewall to the outside IP of the other client
// And then send a message from that client on the outside of the firewall to the inside.
// Both clients can be behind a firewall.
GLOBAL sock% // The socket connection
GLOBAL port% = 15000 // Port number to use
LOCAL ok%, ip%, rv%, msg$
LOCAL myip$
LOCAL destip$
LOCAL timeout
LOCAL src_ip%, src_port% // The ip-address and port of the last packet
myip$ = NETGETIP$() // Get our local IP just for the show
log("Our IP: "+ myip$)
STDOUT "\nDestination IP: "
destip$ = STDIN$()
// Just for less typing when testing
IF destip$ = "" THEN destip$ = "your_ip"
ok = SOCK_INIT() // Init network
IF ok
sock = SOCK_UDPOPEN(port) // Get the socket so we can send/recieve on the port
IF sock <> -1
SOCK_SETBLOCKING sock, FALSE // Set socket to blocking(true), wait until message was sent or recieved
ip = SOCK_GETIP(destip$) // Convert the string to an integer IP
// Send 32 packets, waiting one second for an answer between each send
FOR n = 0 TO 31
log("Sending message: "+"Hello from "+myip$+" To: "+destip$)
ok = SOCK_UDPSEND(sock, "Hello from "+myip$, ip, port)
IF ok <> -1
log("message sent with "+ok+" bytes")
timeout = GETTIMERALL() + 1000 // Start timer for one second
WHILE rv <> -1 AND GETTIMERALL() < timeout
rv = SOCK_RECV(sock, msg$, 999)
src_ip = SOCK_GETREMOTEIP(sock)
src_port = SOCK_GETREMOTEPORT(sock)
IF rv>0 THEN log("message recieved: ["+src_ip+"]["+src_port+"]["+msg$+"]")
IF rv=-1
log(NETGETLASTERROR$()) // Didn't work, tell user why
SOCK_CLOSE(sock)
ENDIF
WEND
ELSE
log(NETGETLASTERROR$())
ENDIF
NEXT
ELSE
log(NETGETLASTERROR$())
ENDIF
ELSE
log(NETGETLASTERROR$())
ENDIF
KEYWAIT
FUNCTION log: str$
STDOUT "\n"+str$
ENDFUNCTION
I haven't tried this code in two years so might need some changes :-)
Hey Moru, thanks for reply and code snippets.
I tried it and it works locally it says message was received etc...
When i send it to Internet IP, it just prompts that its sending but nothing been received.
I did some trial and error trying other unknown IP's but it just prompts the same.
And as I was saying even if it can be tweaked to work, you still need to change router settings and thats what I dont want players to do, players dont want to bother doing that.
It can be done because the games I play dont require any crappy router tweaking and all online apps I have played are the same.
Maybe theres a special port or something, to be honest Im lost with this router crap stuff :)
Thanks anyway for the help mate, much appreciated.
You misunderstand me. It does work over the internet without tweaking the router. But to test it you need to do it over the network. Make a friend run it with your IP number and you run yours with his/her IP-number. Then you will see received messages on both computers.
Notice that your first package will always be lost and since it's UDP, there might be more loss too so you have to keep this in mind when building your network layer.
This already worked with the old Quake 2 game. Not sure if it was supposed to work but it sure worked fine thru our linux gateway.
What SpicyPixel was saying seems wise. It really wouldn't take much bandwidth to serve a large number of users, and you could swap over the server just by changing the redirect IP address. In addition, if you host games on devices/computers but just use a server as a central place to keep a list of open and active games then that would take very little bandwidth indeed.
I'm curious about what other options are available for network gaming since Chaos Rematch will be multiplayer. I liked the sound of GameCenter's turn based support for iOS5 but I'd prefer a solution that works across everything, so Android players can square up against players on all versions of iOS as well asPC players, etc.
Hey all.
I test some tcp example, the one in the samples. It works well in the pc but what's special about the iPhone that it does not work?
The ports have been opened in the router so everything is fine which is why it works on the pc's. But it does not work on my two iPods. The ip's used are obviously Internet ones which again works brilliant on the pcs. Can anyone shed some light here. Again before you ask the code is in the Glbasic samples named tcp. Thanks all.