Main Content

Writing a server in Java

Archive - Originally posted on "The Horse's Mouth" - 2010-07-09 07:33:02 - Graham Ellis

My standard recommendation these days is that you don't write your own low level network code - but rather you use standard protocols and classes - i.e. that you use tried and tested ways of exchanging data. And on that basis, you'll find that our public training courses cover things like talking to web servers and services, using SQL servers from your programs, and so on.

But just occasionally, there's still a niche requirement to do something in low level code - perhaps because you're required to work with a protocol that's non-standard, or even because you need your own protocol for some reason. So, yesterday, I found myself doing a public Java course but out of hours also updating an old example that used packages such as java.net to write our very own server - a talker in a single file in Java. I've posting the example to our web site - [source code here] with updates including extra comments. There is also an older article that descibes it more fully [here].




If you came to this page looking for an article on running a Java Server such as Tomcat (a much more common requirement that writing your own), start [here]; that page is our short course description, and we would welcome you for training - however, you'll find links to many of the examples and a great deal of material from that page, even if you can't make it to Melksham, nor do you have enugh people to justify me coming along and giving a course at your office.