Skip to content

Latest commit

ย 

History

History

socketio

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
title keywords description
Socketio
websocket
chat
socketio
chatroom
contrib
A chatroom application using Socket.IO.

WebSocket Chat Example

Github StackBlitz

This example demonstrates how to create a simple chatroom using WebSockets. The chatroom supports multiple users and allows them to send messages to each other.

Prerequisites

  • Go 1.16 or higher
  • Go modules

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/socketio-chat
  2. Install dependencies:

    go mod tidy

Running the Application

  1. Run the application:

    go run main.go
  2. The server will start on http://localhost:3000.

Connecting to the WebSocket

To connect to the WebSocket, use the following URL:

ws://localhost:3000/ws/<user-id>

Message Object Example

Here is an example of a message object that can be sent between users:

{
  "from": "<user-id>",
  "to": "<recipient-user-id>",
  "data": "hello"
}