GithubHelp home page GithubHelp logo

nlepage / envelope Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tgirier/envelope

0.0 0.0 0.0 56 KB

Envelope is a basic chat server using TCP websockets.

License: MIT License

Dockerfile 3.33% Go 96.67%

envelope's Introduction

envelope

Envelope is a basic chat server using TCP websockets.

Envelope broadcasts messages to all connected users.

Built with โค๏ธ in Paris

๐Ÿ™Œ A huge thanks to @bitfield for his mentoring on this project. ๐Ÿ™Œ

Installation

Envelope can be run in two different ways :

  • Using the provided Dockerfile to build a Docker image
  • Importing the package and use the API within another Go Program

Docker

Requires Docker to be installed on your machine.

To build a Docker image and run it locally:

  1. Build the image:
docker build https://github.com/tgirier/envelope.git
  1. Run the container:
docker run -d -p 8080:8080 [YOUR-IMAGE-ID]

Go API

To import the API within your Go program, simply add the following statement to your go package:

import "github.com/tgirier/chat"

Usage

Connect with nc

If to connect to your envelope server using nc, simply run:

nc <HOST> <PORT>

Example - if your envelope server is running locally on port 8080:

nc localhost 8080

If the connection is successful, the following welcome message will be displayed:

Welcome to envelope! Please enter your username:

Enter your username, press Enter. The notification will be boradcasted to all connected users:

<USERNAME> joined envelope

Then, simply enter your message and press Enter to send it to all connected users.

Connect with the provided Go client

Requires the envelope package to be imported within your Go package

To create a new client connected to a given envelope server use ConnectClient. It takes the address of the target envelope server as a string:

client, err := envelope.ConnectClient(<SERVER_ADDRESS>)

Example - For a local server running on 8080:

client, err := envelope.ConnectClient("localhost:8080")

Next, the server will send the welcome message and ask for the username. To handle it, simply use the Read method on the newly created client:

client.Read()

Next, the server will expect a username. Send the username using the Send method:

client.Send("<USERNAME>"+"\n")

โš ๏ธ All strings sent through the Send method must be ended by a newline character. Otherwise the server will not consider that the message is over. โš ๏ธ

Then the client can send messages or read them using the provided methods.

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.