Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Adding Nicknames

Now that you have a basic Express server connected to Socket.IO, you can start adding features. The first feature is to allow users to set a nickname when they join the server. This works in the following way:

1. Users can enter a nickname into a form.

2. The nickname is sent to the server when the form is submitted.

3. The server checks that the nickname is unique.

4. If the nickname is already taken, the server notifies the client.

5. If the nickname does not already exist, it is added to a list of nicknames.

6. The server broadcasts the list of nicknames to all connected clients.

7. Clients receive the broadcast and update the list of nicknames.

Sending Nicknames to the Server

The first step is to add a form to the index.html file so that users can enter their nickname:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint