Networked Gaming

so i have this game sort of like worms where you choose angle and power and attempt to hit your opponent. Im new to java however and i was wondering how hard would it be to make this game networked?

whats some good websites to learn networking in java?

Take a look at Sockets and Java’s tutorial on them:

http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/socket.html

A warning - networked stuff can be pretty damn difficult. If it’s a simple game though it shouldn’t be too much of a problem.

i have been looking at stuff like that. im guessing i want tcp not udp right? and as far as games go its just 2d and turn based, nothing real time. so i would think i only need to pass along 3 or 4 values just to let one person know what the other person did on their turn.

If it’s turn based, TCP will work fine. The potential problem with TCP is that things may lock up while waiting for packets that were never sent or died on delivery. UDP doesn’t have this issue, although packets can be sent in any order or not at all. Any game that needs to send a lot of information (like Warcraft, Team Fortress, etc.) use UDP.

Unless you’re asbsolutely certain you need to use UDP, don’t.

As for popular games like Warcraft, it is not true that they use UDP. Warcraft 3 uses UDP to broadcast the hosting of a game, so that when users over the world refresh their game lists, your game will pop up. Nothing crashes if user X can’t see your game. Hence, UDP. Data transfer and game negotiation is done over TCP. The biggest game out there today, World of Warcraft, also uses TCP.

Really?!? I thought I had read that all those games had to use UDP.

And in my experience with TCP if I’m requesting information too fast it hangs because it doesn’t arrive fast enough. Obviously I’m not as good as Blizzard is, but after reading this : http://www.java-gaming.org/index.php/topic,608.0.html incredibly long discussion that’s the conclusion I came up with. You simply can’t use TCP for “real-time” stuff because it will wait for missing packets. Like when things get all choppy and jump around, that’s because you’re dropping packets. With TCP that wouldn’t be choppiness, it would be freezing up.

I’d say intensive First-Person shooters are games that would benefit from using UDP. It requires lots of packets back and forth, but each packet is relatively small. UDP has less inherent overhead, so the total data amount will be smaller. Also, because the graphics of these games update really quickly (as opposed to human reaction), a missed packet should not be more than a slight hiccup graphically (because the next update comes so fast after).

Remember that very few games can enjoy a “I don’t care” mentality on its sent and received data. And in these situations, the game needs software replacements for the guaranteed delivery contract. This is far from trivial to implement in any software that’s beyond tic-tac-toe.

Yeah I read up on it some more and Warcraft certainly does use TCP, although I was right that most FPS’s use UDP. I must have had some weaksauce code when I’ve written TCP networked programs, because I’ve gotten complete lockups while the server waited for a missing package.

so given all the above you would recommend tcp if im building a 2d, 2 player, turn based game?

in the end i would like to implement a lobby where players could wait and chat and challange one another.
once they finish a match they return to the lobby.

can all this be done using tcp?

also how do you go about developing a game like this? in order to test it do you need a server?

Absolutely do it with TCP. It’s much easier.

And yes you can do all that, although it can get pretty complicated to make lobbies and stuff. You might want to check out something like Game Gardens to do all this for you. Otherwise, yes you’re going to need to set up a server. However, all you need to do for that is to run a server and a client on the same machine, and have the client connect to “localhost” or “127.0.0.1” as either will work.

so how exactly does one go about setting up a game? ive read things saying you can host a server from home but that doesnt sound very reliable or like it can handle much traffic. are there hosting companies out there that will host games? if so what are some? any of them free? how are professional games hosted?

You’ll have hard luck finding somebody who will host a custom application for you. Your best bet at this point is just to plug a machine into your wall and leave it on.

There are companies which lease servers and then you can host any applications on a server which is dedicated to you. Google for server hosting. Where I live, the prices for a virtual server are 30+ EUR/month, and the prices for a dedicated server are 100+ EUR/month.

so what is the upload rate with cable/broadband? will the service provider even let you host a server/have access to port 80?

Yeah but most of those don’t let you run your own server app. I remember doing a search a long time ago and there were a lot of services for hosting counterstrike etc. games, but not for installing my own Java server application. There’s a big difference there because of possible security issues.

yea i did the same search and they will all host cs and call of duty etc. will all internet providers allow you to host a server?

My brother tells me that Amazon’s EC2 service is very straightforward for this type of thing, and they let you configure your “machine” literally amy way you want (you upload an image of the thing). The only catch is that it’s 10 cents per hour, so that’s about $75 a month. Not terrible, but it’s not cheap either and that’s only for the smallest unit of computation and does not factor in bandwidth, which can add significant cost if you see high usage…

Plenty of providers rent virtual private servers where you have root access and can do anything you want,
starting at about $30/mo for low end systems. The only trick is finding a provider that will be reliable and
helpful to such a small account. The provider for my site, www.Boardspace.net is www.steadfast.net and I am
very satisfied with their service.

I was talking about server hosting where you get a root access to the server and can do anything you like with it.

so what about just hosting a site from home to begin with…is it possible with just a basic internet/broadband provider?