Chapter 2. Your first Netty application

 

This chapter covers

  • Setting up the development environment
  • Writing an Echo server and client
  • Building and testing the applications

In this chapter we’ll show you how to build a Netty-based client and server. The applications are simple—the client sends messages to the server, and the server echoes them back—but the exercise is important for two reasons.

First, it will provide a test bed for setting up and verifying your development tools and environment, which is essential if you plan to work with the book’s sample code in preparation for your own development efforts.

Second, you’ll acquire hands-on experience with a key aspect of Netty, touched on in the previous chapter: building application logic with ChannelHandlers. This will prepare you for the in-depth study of the Netty API we’ll begin in chapter 3.

2.1. Setting up the development environment

To compile and run the book’s examples, the only tools you need are the JDK and Apache Maven, both freely available for download.

We’ll also assume that you’re going to want to tinker with the example code and soon start writing your own. Although you can get by with a plain text editor, we strongly recommend the use of an integrated development environment (IDE) for Java.

2.1.1. Obtaining and installing the Java Development Kit

Your OS may already have a JDK installed. To find out, type the following on the command line:

javac -version

2.2. Netty client/server overview

2.3. Writing the Echo server

2.4. Writing an Echo client

2.5. Building and running the Echo server and client

2.6. Summary

sitemap