Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
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 ¶
eio, err := NewServer(nil) if err != nil { log.Fatalln("server error:", err) } httpSvr := httptest.NewServer(eio) defer httpSvr.Close() for { conn, err := eio.Accept() if err != nil { log.Fatalln("accept error:", err) return } go func(conn Conn) { defer conn.Close() fmt.Println(conn.ID(), conn.RemoteAddr(), "->", conn.LocalAddr(), "with", conn.RemoteHeader()) for { typ, r, err := conn.NextReader() if err != nil { log.Fatalln("read error:", err) return } w, err := conn.NextWriter(typ) if err != nil { r.Close() log.Fatalln("write error:", err) return } _, err = io.Copy(w, r) if err != nil { r.Close() w.Close() log.Fatalln("copy error:", err) return } if err = w.Close(); err != nil { log.Fatalln("close writer error:", err) return } if err = r.Close(); err != nil { log.Fatalln("close reader error:", err) return } } }(conn) }
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.
Click to show internal directories.
Click to hide internal directories.