Giter Club home page Giter Club logo

golangwebsocketclient's Introduction

GoLang Websocket

This project was created to test GoLang as a WebSocket Server.

Go Dependencies

go get github.com/gorilla/websocket

go get github.com/satori/go.uuid

Use

go run main.go

Disclaimer

I obtained *ALL* this code and documentation from other sources.

Architecture


package main

import (
  "encoding/json"
  "fmt"
  "net/http"
  "github.com/gorilla/websocket"
  "github.com/satori/go.uuid"
)

    type ClientManager struct {
        clients    map[*Client]bool
        broadcast  chan []byte
        register   chan *Client
        unregister chan *Client
    }

    type Client struct {
        id     string
        socket *websocket.Conn
        send   chan []byte
    }

    type Message struct {
        Sender    string `json:"sender,omitempty"`
        Recipient string `json:"recipient,omitempty"`
        Content   string `json:"content,omitempty"`
    }


At this point the Golang application can be run with the following:

`go run main.go`

Note: You cannot test it in your web browser, but a websocket connection can be established at

`ws://localhost:12345/ws`

golangwebsocketclient's People

Watchers

 avatar  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.