Skip to content

Engine.IO v3/v4 implementation in Go, supporting real-time bidirectional communication with WebSocket and polling transports.

License

Notifications You must be signed in to change notification settings

lewisgibson/go-engine.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Engine.IO v3/v4 implementation in Go, supporting real-time bidirectional communication with WebSocket and polling transports.

Resources

License

Stars

Watchers

Forks