Coder Social home page Coder Social logo

smallchat's Introduction

Chat Server in Go

This repository is a Go language-based transformation of the original smallchat by antirez. We present a simple yet powerful chat server written in Go, leveraging the concurrency and network libraries of Go to provide a robust chat service that handles multiple clients over TCP connections.

Features

  • Multi-client support using TCP connections.
  • Nickname setting for clients with the /nick command.
  • Broadcast messages to all connected clients.
  • Max client limitation to prevent overloading the server.
  • Graceful handling of client disconnection.

Getting Started

Prerequisites

Before you can run this server, you need to have Go installed on your system. You can download and install Go from the official site.

Installing

To start using this chat server, you need to clone this repository to your local machine. You can do this by running the following command:

git clone https://github.com/yaocanwei/smallchat.git

After cloning the repository, navigate to the directory where the repository is located and build the server using the Go build command:

go build

Running the Server

To run the server, simply execute the built binary:

./main

The server will start and listen for incoming TCP connections on port 7712.

Connecting Clients

To connect a client to the server, use any TCP client, such as netcat or telnet:

telnet localhost 7712

Once connected, you can set your nickname using the /nick command followed by your desired nickname:

/nick YourNickname

After setting a nickname, any text you type will be sent to all connected clients.

Architecture

The server uses a concurrent design where each client connection is handled in a separate goroutine. This allows for scalability and responsive client handling.

  • ChatSystem struct - Holds the core chat logic, including observer management and message broadcasting.
  • Client struct - Represents a connected client and is responsible for sending and receiving messages.

Code Structure

  • main.go - The entry point of the server that initializes the chat system and listens for client connections.

Development

Feel free to fork and extend the functionality of this chat server. You can add new features like private messaging, chat rooms, and user authentication as needed.

Contributions

Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

This project is open-sourced under the MIT License. See the LICENSE file for details.


The README template provided above should be added to your repository with modifications reflecting your specific GitHub username and repository information where applicable. Make sure to add a LICENSE file containing the MIT License text to your repository as well.

smallchat's People

Contributors

yaocanwei avatar

Stargazers

 avatar  avatar  avatar  avatar 陪我去看海吧 avatar  avatar  avatar TsaiKoga avatar  avatar Vincent Guo avatar Feliciano Long avatar kybom avatar S1ahs3r avatar Yuan avatar  avatar eddiehsu avatar k.12f avatar Ziyang avatar yushiwho avatar  avatar  avatar  avatar nixiaobai avatar LU XIUYUAN avatar  avatar rok avatar  avatar Milan Nikolic avatar  avatar Rex avatar Steve Coffman avatar sane avatar Laitron avatar mfy avatar wjx0820 avatar  avatar Yutong LI avatar Wang Ningkai avatar Sleek Zheng avatar Paranoid_K avatar LumaCong avatar  avatar 梧匠 avatar  avatar  avatar Liu Hao avatar

Watchers

 avatar

smallchat's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.