README
¶
go-engine.io
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
Install the package with:
go get gogs.buffalo-robot.com/gogs/imessage/socketio/engineio@v1
Import it with:
import "gogs.buffalo-robot.com/gogs/imessage/socketio/engineio"
and use engineio
as the package name inside the code.
Example
Please check example folder for details.
package main
import (
"encoding/hex"
"io/ioutil"
"log"
"net/http"
"gogs.buffalo-robot.com/gogs/imessage/socketio/engineio"
)
func main() {
server, _ := engineio.NewServer(nil)
go func() {
for {
conn, _ := server.Accept()
go func() {
defer conn.Close()
for {
t, r, _ := conn.NextReader()
b, _ := ioutil.ReadAll(r)
r.Close()
w, _ := conn.NextWriter(t)
w.Write(b)
w.Close()
}
}()
}
}()
http.Handle("/engine.io/", server)
log.Println("Serving at localhost:5000...")
log.Fatal(http.ListenAndServe(":5000", nil))
}
License
The 3-clause BSD License - see LICENSE for more details
Documentation
¶
Index ¶
Examples ¶
Constants ¶
const ( // TEXT is text type message. TEXT = FrameType(base.FrameString) // BINARY is binary type message. BINARY = FrameType(base.FrameBinary) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface { ID() string NextReader() (FrameType, io.ReadCloser, error) NextWriter(typ FrameType) (io.WriteCloser, error) Close() error URL() url.URL LocalAddr() net.Addr RemoteAddr() net.Addr RemoteHeader() http.Header SetContext(v interface{}) Context() interface{} }
Conn is connection.
type Options ¶
type Options struct { RequestChecker func(*http.Request) (http.Header, error) ConnInitor func(*http.Request, Conn) PingTimeout time.Duration PingInterval time.Duration Transports []transport.Transport SessionIDGenerator SessionIDGenerator }
Options is options to create a server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is server.
Example ¶
Output:
type SessionIDGenerator ¶
type SessionIDGenerator interface {
NewID() string
}
SessionIDGenerator generates new session id. Default behavior is simple increasing number. If you need custom session id, for example using local ip as perfix, you can implement SessionIDGenerator and save in Configure. Engine.io will use custom one to generate new session id.