Git Product home page Git Product logo

gows's Introduction

About

This project is simple and light but very powerful implementation of Browser side Websockets with Go server. It is used in TreeScale.com as a part of dashboard live Docker container builds and manage.

Server Example

Take a look on this simple implementation. It is super easy to get started and make awesome evented things almost with the same simple API as Socket.io have.

package main

import (
	"fmt"
	"time"
	"treebuild/tree_socket"
)

func main() {
	tree_socket.On("connection", func(i_sock interface{}) {
		sock := i_sock.(*tree_socket.Socket)
		sock.On("api_init", func(data interface{}) {
			fmt.Println(data)
			i := 0
			for {
				sock.Emit("test_emit", map[string]int{"net_data": i})
				i++
				time.Sleep(time.Second * 1)
			}
		})

		sock.On("disconnect", func(i_sock interface{}) {
			fmt.Println("Disconnected")
		})
	})

	tree_socket.Listen(":3000", "/")
}

Client Side Example

With JavaScript in TreeScale.com we are using plain Websocket implementation so it will work on most browsers and you don't need to include 90Kb+ Socket.io library to do basic evented systems.

var socket = require("./lib/socket");  // in this case we have socket.js file in lib directory

socket.connect("localhost:3000");
socket.on("test_emit", function (data) {
    console.log(data);
});

socket.on("connection", function (data) {
    console.log("connected", data);
    socket.emit("api_init", {test: 15});
});

Is this useful for you ?

Let me know if you want to add Websocket event Rooms, Groups or any other special things for make this light thing more functional. I'm ready to help.
With ❤️ from TreeScale Inc.

gows's People

Stargazers

Andrey Andrade avatar

Watchers

James Cloos avatar Tigran Bayburtsyan 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.