WebSocket emulation - Go server
Go
Switch branches/tags
Nothing to show
Pull request Compare This branch is 2 commits ahead, 211 commits behind igm:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples/echo
sockjs
testserver
.gitignore
README.md

README.md

What is SockJS?

SockJS is a JavaScript library (for browsers) that provides a WebSocket-like object. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication channel between the browser and the web server, with WebSockets or without. This necessitates the use of a server, which this is one version of, for GO.

SockJS-Go server

SockJS-Go is a Node.js server side counterpart of SockJS-client browser library written in CoffeeScript.

To install sockjs-go run:

go get github.com/igm/sockjs-go/sockjs

A simplified echo SockJS server could look more or less like:

package main

import (
	"github.com/igm/sockjs-go/sockjs"
	"log"
	"net/http"
)

func main() {
    sockjs.Install("/echo", EchoHandler, sockjs.DefaultConfig)
	err := http.ListenAndServe(":8080", nil)
	log.Fatal(err)
}

func EchoHandler(conn sockjs.Conn) {
	for {
		if msg, err := conn.ReadMessage(); err == nil {
			go conn.WriteMessage(msg)
		} else {
			return
		}
	}
}

SockJS Protocol Tests Status

ERROR: test_haproxy (__main__.WebsocketHixie76)
ERROR: test_firefox_602_connection_header (__main__.WebsocketHybi10)
ERROR: test_headersSanity (__main__.WebsocketHybi10)
FAIL: test_streaming (__main__.Http10)

Ran 68 tests in 1.441s
FAILED (failures=1, errors=3)

Important

This library is not production ready and use is not recommended.