Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Basic chat Applications with Socket IO
Rating: 3.9 out of 5(6 ratings)
923 students

Basic chat Applications with Socket IO

Introduction to create a basic chat application node js
Created byJittavee somsri
Last updated 11/2023
English

What you'll learn

  • A Beginner's Guide to Real-Time Chat Web Development
  • node js Real-Time Chat
  • Socket IO in Action: Building Real-Time Apps javascript
  • Geared towards students and enthusiastic individuals interested in real-time web development
  • Javascript node js Real-Time Chat

Course content

1 section14 lectures37m total length
  • Basic chat Applications with Socket IO0:40
  • Content0:33
  • Introduction3:20
  • Step #1: Project initialization1.12:12
    • Step #1: Project initialization

    The first goal is to set up a simple HTML webpage that serves out a form and a list of messages. We’re going to use the Node.JS web framework express to this end. Make sure Node.JS is installed.

    First let’s create a package.json manifest file that describes our project. I recommend you place it in a dedicated empty directory (I’ll call mine socket-chat-example).

  • You can run this example directly in your browser1.1.13:10
  • Step #1: Project initialization1.23:18
  • Step #1: Project initialization1.31:11
  • Step #2: Serving HTML23:18
    • Step #2: Serving HTML

    So far in index.js we’re calling res.send and passing it a string of HTML. Our code would look very confusing if we just placed our entire application’s HTML there, so instead we're going to create a index.html file and serve that instead.

  • You can run this example directly in your browser2.2.15:09
  • Step #3: Integrating Socket.IO4:46
    • Step #3: Integrating Socket.IO

    Socket.IO is composed of two parts:

    • A server that integrates with (or mounts on) the Node.JS HTTP Server (the socket.io package)

    • A client library that loads on the browser side (the socket.io-client package)

    During development, socket.io serves the client automatically for us, as we’ll see, so for now we only have to install one module:

  • Step #4: Emitting events2:38
  • You can run this example directly in your browser 4.12:15
  • Step #5: Broadcasting 5.12:02
    • Step #5: Broadcasting

    The next goal is for us to emit the event from the server to the rest of the users.

    In order to send an event to everyone, Socket.IO gives us the io.emit() method.

  • Step #5: Broadcasting 5.22:51
    • Step #4: Emitting events

    The main idea behind Socket.IO is that you can send and receive any events you want, with any data you want. Any objects that can be encoded as JSON will do, and binary data is supported too.

    Let’s make it so that when the user types in a message, the server gets it as a chat message event. The script section in index.html should now look as follows:

Requirements

  • Visual Studio Code is source code editor,node js, javascript

Description

Lesson Title: Introduction to Socket IO

Objective: By the end of this lesson, students will understand the basics of Socket IO and its significance in real-time web applications.

Socket IO is an open-source, cross-platform library that provides full-duplex bidirectional communication between a client and a server based on events. It is built on the WebSocket protocol, providing additional capabilities such as automatic reconnection and fallback to HTTP long polling where WebSockets cannot be used.

Automatic reconnection​

Under some particular conditions, the WebSocket connection between the server and the client can be interrupted with both sides being unaware of the broken state of the link.

That's why Socket IO includes a heartbeat mechanism, which periodically checks the status of the connection.

And when the client eventually gets disconnected, it automatically reconnects with an exponential back-off delay, in order not to overwhelm the server.

Packet buffering​

The packets are automatically buffered when the client is disconnected, and will be sent upon reconnection.

More information

How it works

The bidirectional channel between the Socket IO server (Node js) and the Socket IO client (browser, Node js, or another programming language) is established with a WebSocket connection whenever possible, and will use HTTP long-polling as fallback.

Materials:

- A computer with Node.js installed

- Internet access

- Code editor (e.g., Visual Studio Code)

- Node js

- Javascript

Who this course is for:

  • Beginners