One way to easily test your server is to use the
wscat
npm
module. wscat
is a tool for connecting to and communicating with
a WebSockets server. The module provides a command-line program that
you will use as a chat client.
Open a second terminal
window and install wscat
globally. You may need to
run this command with administrator privileges. (If you need a refresher,
refer to Chapter 1.)
npm install -g wscat
When wscat
is installed, you are ready to connect to your WebSockets
server.
In the second terminal window, run the command
wscat -c ws://localhost:3001
. You should see
the message connected (press CTRL+C to quit)
in the second terminal window
and 'client connection established'
in the first window.
In the second terminal window, enter some text at the prompt. Each time you type some text and press the Return key, your text will be repeated by the WebSockets server, as shown in Figure 16.3.
Now that you have confirmed that you are able to communicate with your server via WebSockets, it is time to add the real functionality that will power Chattrbox’s chat system.
13.58.51.36