package module
Version: v0.0.0-...-50567eb Latest Latest

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

Go to latest
Published: Oct 30, 2014 License: BSD-3-Clause Imports: 12 Imported by: 0



GoDoc Build Status

go-engine.io is the implement of engine.io in golang, which is transport-based cross-browser/cross-device bi-directional communication layer for go-socket.io.

It is compatible with node.js implement, and supported long-polling and websocket transport.


Install the package with:

go get github.com/googollee/go-engine.io

Import it with:

import "github.com/googollee/go-engine.io"

and use engineio as the package name inside the code.


Please check example folder for details.

package main

import (


func main() {
	server, err := engineio.NewServer(nil)
	if err != nil {

	go func() {
		for {
			conn, _ := server.Accept()
			go func() {
				defer conn.Close()
				for i := 0; i < 10; i++ {
					t, r, _ := conn.NextReader()
					b, _ := ioutil.ReadAll(r)
					if t == engineio.MessageText {
						log.Println(t, string(b))
					} else {
						log.Println(t, hex.EncodeToString(b))
					w, _ := conn.NextWriter(t)

	http.Handle("/engine.io/", server)
	http.Handle("/", http.FileServer(http.Dir("./asset")))
	log.Println("Serving at localhost:5000...")
	log.Fatal(http.ListenAndServe(":5000", nil))


The 3-clause BSD License - see LICENSE for more details



go-engine.io is the implement of engine.io in golang, supported long-polling and websocket transport.

It is compatible with node.js implement.



View Source
const Protocol = 3


This section is empty.


This section is empty.


type Conn

type Conn interface {

	// Id returns the session id of connection.
	Id() string

	// Request returns the first http request when established connection.
	Request() *http.Request

	// Close closes the connection.
	Close() error

	// NextReader returns the next message type, reader. If no message received, it will block.
	NextReader() (MessageType, io.ReadCloser, error)

	// NextWriter returns the next message writer with given message type.
	NextWriter(messageType MessageType) (io.WriteCloser, error)
	// contains filtered or unexported methods

Conn is the connection object of engine.io.

type MessageType

type MessageType int
const (
	MessageText MessageType = iota

func (MessageType) String

func (t MessageType) String() string

type Server

type Server struct {
	// contains filtered or unexported fields

Server is the server of engine.io.

func NewServer

func NewServer(transports []string) (*Server, error)

NewServer returns the server suppported given transports. If transports is nil, server will use ["polling", "webosocket"] as default.

func (*Server) Accept

func (s *Server) Accept() (Conn, error)

Accept returns Conn when client connect to server.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles http request.

func (*Server) SetAllowRequest

func (s *Server) SetAllowRequest(f func(*http.Request) error)

SetAllowRequest sets the middleware function when establish connection. If it return non-nil, connection won't be established. Default will allow all request.

func (*Server) SetAllowUpgrades

func (s *Server) SetAllowUpgrades(allow bool)

SetAllowUpgrades sets whether server allows transport upgrade. Default is true.

func (*Server) SetCookie

func (s *Server) SetCookie(prefix string)

SetCookie sets the name of cookie which used by engine.io. Default is "io".

func (*Server) SetPingInterval

func (s *Server) SetPingInterval(t time.Duration)

SetPingInterval sets the interval of ping. Default is 25s.

func (*Server) SetPingTimeout

func (s *Server) SetPingTimeout(t time.Duration)

SetPingTimeout sets the timeout of ping. When time out, server will close connection. Default is 60s.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL