Skip to content

Latest commit

 

History

History
79 lines (60 loc) · 2.23 KB

README.md

File metadata and controls

79 lines (60 loc) · 2.23 KB

go-engine.io

Build Workflow Pkg Go Dev

An implementation of the engine.io v4 protocol and client in go.

Resources

Features

Installation

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

Quickstart

client, _ := engineio.NewSocket("http://localhost:3000/engine.io/", engineio.SocketOptions{
    Client: &http.Client{
        Timeout: time.Second * 30,
    },
    Header: &http.Header{
        "Authorization": []string{"Bearer token"},
    },
    Upgrade:         engineio.Pointer(true),
    RememberUpgrade: engineio.Pointer(true),
    Transports: &[]engineio.TransportType{
        engineio.TransportTypePolling,
        engineio.TransportTypeWebSocket,
    },
})

// Bind an open handler.
client.OnOpen(func() {
    client.Send(ctx, []engineio.Packet{
        {Type: engineio.PacketMessage, Data: []byte("Hello")},
    })
})

// Bind a message handler.
client.OnMessage(func(data []byte) {
    fmt.Printf("Message from server: %s\n", string(data))
})

// Bind a close handler.
client.OnClose(func(reason string, cause error) {
    fmt.Printf("Close: %v, %v\n", reason, cause)
})

// Bind an error handler.
client.OnError(func(err error) {
    fmt.Printf("Error: %v\n", err)
})

// Open the client.
client.Open(context.Background())

// Wait for 10 seconds.
<-time.After(time.Second * 10)

// Close the client.
client.Close(context.Background())

Todo

  • Server implementation
  • Parse v2/v3 protocol