Giter Club home page Giter Club logo

chat-application's Introduction

Overview

This is a simple chat application that allows users to send and receive messages in real-time using WebSockets. The application supports functionalities like user authentication, creating/joining/leaving chat rooms, sending direct messages, and broadcasting messages to all users in a chat room. It also includes a command-line interface (CLI) for interaction and supports saving chat history and user data to files.

Features

  • Real-time communication using WebSockets.
  • User authentication.
  • Chat rooms: Users can create, join, and leave chat rooms.
  • Direct messages: Users can send private messages to other users.
  • Persistent storage: Chat history and user data are saved to JSON files.
  • Error handling for various scenarios such as connection errors.
  • Command-line interface for user interaction.

Technologies Involved

  • Go: The programming language used to build the application.
  • Gorilla WebSocket: A Go package used to implement WebSocket connections.
  • Cobra: A library for creating powerful CLI applications in Go.
  • Promptui: A library for creating interactive prompts in CLI applications.
  • Sync: For handling concurrent access to shared resources.
  • JSON: For saving and loading user data and chat history.
  • Docker: For containerizing the application (still in troubleshooting).

Code Structure

  • main.go: The main entry point of the application.
  • User, ChatRoom structs: Represent users and chat rooms.
  • serverCmd and clientCmd: Cobra commands for starting the server and client respectively.
  • handleConnections, authenticateUser, handleMessage: Functions to handle WebSocket connections, authentication, and message handling.
  • createRoom, joinRoom, leaveRoom, broadcastMessage, sendDirectMessage: Functions for managing chat rooms and messages.
  • saveData, loadData, saveToFile, loadFromFile: Functions for saving and loading data to/from JSON files (chat.json, users.json).
  • promptUser, registerUser: Functions for CLI interaction and user registration.

How to Run the Demo

Prerequisites

  • Go installed on your machine. You can download it from here.

  • Git installed on your machine to clone the repository.

  • wscat installed. You can install it globally via npm:

    npm install -g wscat

Steps

  1. Clone the repository:

    git clone <repository-url>
    cd <repository-directory>
  2. Build the application:

    go mod download
    
    go build -o chatapp main.go
  3. Run the server:

    ./chatapp server

    The server will start and listen for WebSocket connections on ws://localhost:8080/ws.

  4. Test the WebSocket connection (optional):

    Open another terminal window and run:

    wscat -c ws://localhost:8080/ws

    This will connect to the WebSocket server, and you can manually send messages for testing.

  5. Run the client:

    Open another terminal window and run:

    ./chatapp client

    Follow the prompts to register, login, create/join chat rooms, and send messages.

Using the CLI

  • Register: Register a new user with a username and password.
  • Login: Login with your registered username and password.
  • Create Room: Create a new chat room.
  • Join Room: Join an existing chat room.
  • Leave Room: Leave a chat room.
  • Send Message: Send a message to a chat room.
  • Direct Message: Send a private message to another user.
  • Quit: Exit the application.

Known Issues

Docker

Currently, Docker support is under development and troubleshooting. The plan is to containerize the application using Docker and provide a Dockerfile and docker-compose.yml file for easy setup and deployment. Once the issues are resolved, an updated version of this documentation will include instructions on how to use Docker to run the application.

User Registration and Login

There are known issues with the user registration and login process:

  • Users may encounter errors during registration or login.
  • These issues are being actively investigated and addressed.

Chat Room Functionality

The chat room functionality is still buggy:

  • Users can create and join chat rooms.
  • However, after joining or creating a room, users may experience issues when trying to chat like in a common chat application view.
  • This is currently a work in progress, and improvements are being made to ensure smooth chatting within rooms.

Troubleshooting

Common Issues

  1. WebSocket connection fails:

    • Ensure the server is running and listening on the correct port.
    • Check for network issues that may be blocking WebSocket connections.
  2. Authentication fails:

    • Verify that the username and password are correct.
    • Ensure that the user data is correctly saved and loaded from the users.json file.
  3. Messages not being delivered:

    • Check if the user is correctly joined to the chat room.
    • Ensure there are no issues with the WebSocket connection.

chat-application's People

Contributors

andregit1 avatar

Stargazers

 avatar

Watchers

 avatar

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.