Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


QuickServer
Java Library for building TCP servers

Recently I have been tasked with building an IMAP server.  Not a true IMAP server we are merely using IMAP as an interface to another system.  So I am developing the proxy class library which involves writing all the communications and command processing for the IMAP protocol.  I first had a look around at various projects to see if there was something I could hook into quickly.  Sadly the Apache JAMES project isn't supporting IMAP yet and even if it did, it would still be a little heavy for our requirements.  The quickest thing is to implement the handful of commands from the IMAP protocol that we needed.

IMAP works in the same manner as other TCP protocols (SMTP, POP, HTTP) in that line-terminated strings are passed back and forth with a known format so the client and server can communicate easily.  I have written many of these types of servers in the past and was looking forward to trying my hand at it again.  However on a trawl in Google for something completely different, I discovered a gem of an open-source project; QuickServer.

QuickServer is a Java library that takes all the hassle and logistics away from building TCP servers.  It is a complete framework that performs all the underlying communications and allows you to get on with implementing the commands.  It sits in one JAR and the installation took only a matter of minutes to get going.   So how does it work?  Looking at a very basic example, you define a class that implements the ClientCommandHandler class.  Each method is used for each state of the connection.  One for when the client first connects, one for when it closes, and another for when the connection is lost.  When a message is received the handleCommand() method is triggered passing in the command that was read.

public class sampleCommandHandler implements ClientCommandHandler {
	
  public void gotConnected(ClientHandler handler) throws SocketTimeoutException, IOException {
    handler.sendSystemMsg( "New client " + handler.getSocket().getInetAddress() );
    handler.sendClientMsg( "* OK Sample Framework $Revision: 1.5 $ ready" );
  }

  public void lostConnection(ClientHandler handler) throws IOException {
    handler.sendSystemMsg("Connection lost : " + handler.getSocket().getInetAddress());
  }

  public void closingConnection(ClientHandler handler)throws IOException {
    handler.sendSystemMsg("Connection closed : "+handler.getSocket().getInetAddress());
  }

  public void handleCommand(ClientHandler handler, String command)
                            throws SocketTimeoutException, IOException {
    if ( command.getCommand().equals("LOGIN") ){
      processingLOGIN( handler );
    else
      handler.sendClientMsg( " BAD Command unknown " + command );
  }
}

It is a wonderfully easy and robust library to be using.  The example here doesn't do it justice, but in the sample applications that come with it, is a full FTP server.  The library also lets you control the total number of concurrent client connections, logging facilities and various other nuggets. The only niggle I have is that while you can easily log everything the server receives, you can't log data leaving the server.  A slight omission to what is otherwise a very complete package.  The library is released under the Lesser-General Public License so you can easily use it any of your projects.

If you need to build a TCP server (and let's face it, it is very rare these days you have to) then check out QuickServer.  It is well worth it.

Republished from Alan Williamson's blog
About Alan Williamson
Alan Williamson is widely recognized as an early expert on Cloud Computing, he is Co-Founder of aw2.0 Ltd, a software company specializing in deploying software solutions within Cloud networks. Alan is a Sun Java Champion and creator of OpenBlueDragon (an open source Java CFML runtime engine). With many books, articles and speaking engagements under his belt, Alan likes to talk passionately about what can be done TODAY and not get caught up in the marketing hype of TOMORROW. Follow his blog, http://alan.blog-city.com/ or e-mail him at cloud(at)alanwilliamson.org.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

It does not look to be an error i use QS ClientCommandHandler is an interface and not a class.

Yikes!
Fundamental Java error!

In the article: "Looking at a very basic example, you define a class that implements the ClientCommandHandler class."

This is a classic Java novice error. On the face of it, the sentence doesn''t make sense. Can you spot the problem?

Yes, obviously a Java class doesn''t implement another Java class; Java classes may extend other classes or implement interfaces.

Silly, Alan, you shouldn''t be making these errors.


Your Feedback
Naveen wrote: It does not look to be an error i use QS ClientCommandHandler is an interface and not a class.
Chris Gerrard wrote: Yikes! Fundamental Java error! In the article: "Looking at a very basic example, you define a class that implements the ClientCommandHandler class." This is a classic Java novice error. On the face of it, the sentence doesn''t make sense. Can you spot the problem? Yes, obviously a Java class doesn''t implement another Java class; Java classes may extend other classes or implement interfaces. Silly, Alan, you shouldn''t be making these errors.
Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE