gosockjs

package module
v0.0.0-...-c707376 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2012 License: MIT Imports: 17 Imported by: 0

README

gosockjs

A Go language implementation of a SockJS server. The protocol is partly specified in a test suite. Read that for details. To run the suite against gosockjs, go run test_server/server.go

Supported protocols:

  • websocket
  • xhr-xtreaming
  • iframe-eventsource
  • iframe-htmlfile
  • xhr-polling
  • iframe-xhr-polling
  • jsonp-polling

The xdr protocols may work, but have not been tested. Raw-websocket also works.

Websocket version 7 is not supported. Nor is HTML 1.0.

UNDER CONSTRUCTION. Do not lightly assume that it works!

There is a test server in test_server that can be used with the sockjs-protocol suite (go run test_server/server.go). There is a simple client that acts as a quick smoke/sanity test in test_client.

Some TODOs and issues:

  • Bulletproof thread issues.
  • Real testing. There are some tests here, but not nearly enough. The sockjs-protocol tests are not at all thorough.
  • What about https?
  • The polling and streaming protocols do not allow keep-alive. That is due to limitations in the Go net and http packages -- or at any rate that's what it looks like to me. Workarounds are possible but are not obviously a good idea.

Tests that are currently failing from the protocol test suite:

  • WebsocketHixie76.test_haproxy. Fixing this would mean changes to (a fork of) go.net/websocket.
  • Http10.test_streaming.
  • WebsocketHybi10.test_firefox_602_connection_header. That test uses websocket version 7, not supported by go.net/websocket.

I have no plans to fix any of these, as I see little point in supporting http1.0 and antique versions of Firefox.

Documentation

Overview

Package gosockjs is an implementation of a SockJS server.

See https://github.com/sockjs .

SockJS is intended to be used much like websockets, and gosockjs attempts to mirror the websocket interface, with the complication that the infrastructure needs to know the base url in order to set up all the routing. A simple gosockjs server looks like

func echo(c *gosockjs.Conn) {
	io.Copy(c, c)
}

func main() {
	gosockjs.Install("/echo", echo)
	http.ListenAndServe(":8081", nil)
}

Index

Constants

This section is empty.

Variables

View Source
var EmptyPayload error = errors.New("Payload expected.")
View Source
var JSONError error = errors.New("Broken JSON encoding.")

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a SockJS connection. It is a ReadWriteCloser

type Handler

type Handler func(*Conn)

Handler is an interface to a SockJS connection.

type Router

type Router struct {
	WebsocketEnabled bool
	CookieNeeded     bool
	DisconnectDelay  time.Duration
	HeartbeatDelay   time.Duration
	// contains filtered or unexported fields
}

Router handles all the SockJS requests.

func Install

func Install(baseUrl string, h Handler) (*Router, error)

Install creates and installs a Router into the default http ServeMux. baseUrl should be an absolute path.

func NewRouter

func NewRouter(baseUrl string, h Handler) (*Router, error)

NewRouter returns a new gosockjs router listening at baseUrl. baseUrl should be an absolute path.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

Notes

Bugs

  • xhr connections cannot be reused.

Directories

Path Synopsis
A very simple client for testing gosockjs.
A very simple client for testing gosockjs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL