/smallchat

Antirez smallchat implemented by golang. A simple chat server implemented in Go, allowing multiple clients to connect, exchange messages, and set nicknames.

Primary LanguageGoApache License 2.0Apache-2.0

Go SmallChat Server

A simple chat server implemented in Go, allowing multiple clients to connect, exchange messages, and set nicknames. This reposity reference from smallchat.

Table of Contents

Features

  • Multiple clients can connect to the server.
  • Clients can set their nicknames using the /nick command.
  • Messages sent by clients are broadcasted to all connected clients.
  • Supports messages with newlines.

Prerequisites

  • Go (Go 1.21 or higher recommended)

Usage

  1. Change to the project directory:

    cd go-chat-server
  2. Build the server:

    go build chat_server.go
  3. Run the server:

    ./main
  4. Open multiple terminal windows and use telnet or netcat to connect to the server:

    nc localhost 7711
  5. Set your nickname using the /nick command:

    /nick MyNickname
  6. Start sending messages, including newlines:

    Hello, everyone!
    This is a multiline message.

Application Example

go run chat_server.go
  1. Start the server, and it will begin listening for client connections.

  2. Open multiple terminal windows and connect to the server using telnet or netcat.

  3. Set nicknames for each client using the /nick command.

  4. Clients can send messages, and the server will broadcast these messages to all other clients.

    Example:

    arduinoCopy code
    [Client 1] /nick Alice
    [Client 2] /nick Bob
    [Client 1] Hello, Bob!
    [Client 2] Hi, Alice!
    

License

This project is licensed under the Apache-2.0 License.