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

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
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.
Latest Cloud Developer Stories
Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
With Cloud Expo 2012 New York (10th Cloud Expo) now under 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 techn...
Nimble, the social CRM platform has announced the launch of Nimble 2.0, billed as the “most social” CRM platform on the market today. Nimble was designed entirely with social CRM in mind and is the first social business platform that empowers companies with the ability to get clo...
2011 was a year of rapid adoption for public and private cloud services. Instant and on-demand server provisioning was the driving force behind the massive growth. On top, cloud server templates and script automation simplified application installation for simple and pre-defined ...
"Having been in the IT field for many years, I believe the cloud computing chapter in the industry is an exciting one and I am proud to be a part of it," said National Reconaissance Office (NRO) Chief Information Officer Jill T. Singer Tuesday, as it was announced that she was on...
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

Breaking Cloud Computing News
Joyent Cloud, the highest performance public cloud, and Amplify, a startup accelerator focused on su...