Quake tools with Java and UDP
Author: vglass@jfind.com, Van Glass
Quake is probably the most popular game on the net today. If you haven't played Quake or at the very least heard
of it, perhaps you have been living in a cave for the past five years. Like many other popular games
Quake can be played over the Internet in multi player mode. However, to play with other people on the net you must
connect to a Quake server.
There are literally thousands of public game servers on the net which you can join. Likewise there are several
software tools out there which can assist you in locating and connecting to these servers. GameSpy is one of the few
utilities available for easy download and use. GameSpy lists publicly available servers, server stats, player stats
and more. All of this information is served using the UDP protocol. This article will briefly explain the UDP protocol and
how using Java we can develop our own tool for retrieving server and player stats from a Quake server.
What is UDP?
UDP is not unlike TCP. UDP runs atop the IP layer allowing you to send and receive packets of information across a network. The main difference between
UDP and TCP is reliability. UDP is not a reliable communications protocol. It is unreliable because packets are not guaranteed
to arrive in the order sent, or at all for that matter. TCP on the other hand is a reliable protocol. Packets sent are guaranteed
to arrive in the order sent and if a TCP packet is lost in transit then
a retransmission will be requested.
So why use UDP? Although UDP is unreliable it more than makes up for this deficiency with speed. By getting rid of the overhead that TCP uses in ensuring
reliability, UDP is able to process packets much faster than TCP. In a "real-time" network game like Quake speed is all important which is why
Quake uses UDP as it network communications protocol.
Connecting to Quake Server.
Opening a connection to a Quake server is relatively straight forward, especially in Java.
Quake servers perform all network communications using UDP. Typically communications
are performed over UDP port 27960. However depending on how many simultaneous games a server has running this can vary between
ports 27960-27963. Quake servers understand a handful of commands. The Quake API which
explains these commands can be found here. We are only concerned with the "getstatus" command which will give us information about
server configuration as well as player stats.
Making things a bit tricker is the Quake servers requirement that requests be sent
using OOB (out-of-band) data packets. The full definition
of OOB data packets is out of scope for this article; however we will address how to create OOB packets.
To make a UDP connection we need to look at using the DatagramSocket and DatagramPacket classes.
The DatagramSocket class is what will be used to send and receive UDP data. This is different than TCP since Java requires
a Socket instance to send and a ServerSocket instance to receive data.
DatagramSocket ds = new DatagramSocket();
Next
| Sponsored Links - please visit our sponsors |
| SSH Factory | | automate telnet and SSH tasks | | http://www.jscape.com/sshfactory/ |
| Java SMTP Component | | Easily add SMTP to your Java apps | | http://www.jscape.com/inetfactory/smtp.html |
| Learn Java Server Faces! | | Use WebGalileo Faces JSF components to quickly create Java based web apps. | | http://www.jscape.com/webgalileofaces/ |
| Secure FTP Applet | | Connect to FTP securely from within your browser. | | http://www.jscape.com/sftpapplet/ |
| Java POP3 Component | | Easily add POP3 to your Java apps | | http://www.jscape.com/inetfactory/smtp.html |
| FTP Applet | | Add file transfer capabilities to your web pages. | | http://www.jscape.com/ftpapplet/index.html |
Sponsor this site
| |