Chapter 3. Writing a chat application

 

This chapter covers

  • Asking the user for input
  • Creating a command-line interface
  • Parsing and generating JSON
  • Transferring data over the network
  • Using and creating modules

In the previous chapter, you learned the basics of the Nim programming language, including the syntax, some of the built-in types, how to define variables and procedures, how to use control-flow statements, and much more.

In this chapter, you’ll build on and solidify that knowledge by developing a fully functional chat application. You’ll also learn many new concepts that are essential to the development of certain applications. In particular, you’ll do the following:

  • Build a command-line interface, which can be used to ask the user for input.
  • Learn how to use sockets to transfer data over networks, such as the internet.
  • Use a JSON parser to build a simple chat protocol. The application will use this protocol to exchange messages in a standard and consistent manner.
  • Learn how to use modules to separate your code into standalone units, which will make your code more reusable.

With the popularity of the internet, computer networks have become increasingly important. The most basic feature of the internet is the transfer of data, but implementing this feature isn’t always easy at the programming language level. In creating this chapter’s chat application, you’ll learn the basics of transferring data between multiple computers.

3.1. The architecture of a chat application

3.2. Starting the project

3.3. Retrieving input in the client component

3.4. Implementing the protocol

3.5. Transferring data using sockets

3.6. Summary

sitemap