🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Servers in Java

Started by
4 comments, last by Dan Smith 24 years, 8 months ago
Threading is an integral part of the Java language - I've used it a lot and never encountered any problems (besides those that always come from multithreaded programs )

Networking is not an integral part of the language, but it IS a significant part of the core run-time library. IOW: Any platform that supports Java also supports HTTP and sockets (UDP/TCP) out of the box. In addition, these protocols are SOOO easy to use (a lot simpler than winsock for example).

Java for implementing a server? No reason not to - it won't be much different from implementing it in C (except for the built-in HTTP support, which might be hard to come by for a C app). There's (obviously) a slight performance penalty, but I doubt if it'll ever turn into a problem.

You might want to get a good Java book - they all discuss both threading and networking in detail. (Avoid the big fat 1200 page ones, since they're essentially transcripts of the language spec, stuffed with useless repetition, figures and lousy code samples).

/Niels

<b>/NJ</b>
Advertisement
Well, I dont have any money to get a book at the moment...So I have to rely on the web.

Are there any samples anywhere that demonstrate one? Even just a simple chat server that can echo the message sent to the server, to all the other clients.

I have Learn Java Now, It came with J++ 1.0, yet it doesnt cover threading/networking.

-Dan

D. Smith
You could try
http://developer.java.sun.com/developer/codesamples/networking/

But there should be tons of network code samples out there.

/Niels

<b>/NJ</b>
An important thing to consider before implementing a server is how you're clients are going to communicate with it. The simplest way to do it is with the JDK's built in support for TCP/IP and UDP/IP. Then, any client, whether written in C++, Java, Perl or whatever can connect to it.

HOWEVER, if the client lives on the other side of a proxy or a firewall, THIS WON'T WORK! Most proxies and firewalls only allow certain kinds of connections. Most will allow HTTP requests though. To have Java open an HTTP request that will go through firewalls and proxies use something like.

URL url = new URL(...);
url.openConnection();

Check out the URLConnection class to see how to send and receive HTTP requests.

Note that HTTP requests are OK for turn-based games but not realtime!

I was wondering if anyone here has used Visual J++, or any other Java development tool. I just got Visual J++, and I have heard alot about its server capabilities. It seems like a good choice for my server considering one of the major points iny my server is portability.

I was wondering if anyone here has ever written a server in Java.

I'd appreciate if you could give me a list of sites of any sites (Or maybe even some sample code) with information on java, specifically its network and threading functions.


Thanks.

Dan
dans@3dgamedev.com

D. Smith
Actually, wether the game is "real time" or "turn based" is not really the issue.

The key is the amount of latency the game can handle before becomming unplayable. Obviously fast-paced action games such as Quake requires very low ping to be playable. Strategy games (even real-time), though, are much less subject to network latency.

I'll soon open a site with an on-line RTS game that uses HTTP (it's currently in alpha).

/Niels

<b>/NJ</b>

This topic is closed to new replies.

Advertisement