Categorygithub.com/queue-b/gocketio
modulepackage
0.9.9
Repository: https://github.com/queue-b/gocketio.git
Documentation: pkg.go.dev

# README

gocketio

Go (golang) socket.io client

Supports

  • Non-binary Events
  • Binary Events
  • Non-binary Acks
  • Binary Acks
  • Automatic reconnection with exponential backoff
  • Multiplexing multiple namespaces over a single connection
  • Websocket transport

Installation

go get github.com/queue-b/gocketio

Usage

Additional examples are available as godocs.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/queue-b/gocketio"
)

func main() {
	// Connect to a socket.io server at example.com
	manager, err := gocketio.DialContext(context.Background(), "https://example.com/", gocketio.DefaultManagerConfig())

	if err != nil {
		log.Fatal(err)
	}

	// Create a socket for the root namespace
	socket, err := manager.Namespace("/")

	if err != nil {
		log.Fatal(err)
	}

	c := make(chan struct{}, 1)

	// Add a handler for "hello" events
	socket.On("hello", func(from string) {
		fmt.Printf("Hello from %v\n", from)
		c <- struct{}{}
	})

	// Block until someone sends a hello message
	<-c
}

License

Apache

Authors

Alex Kube

# Packages

No description provided by the author
No description provided by the author

# Functions

DefaultManagerConfig returns a ManagerConfig with sane defaults ConnectionTimeout is 20 seconds Backoff is backoff.ExponentialBackoff AdditionalQueryArgs is an empty map.
DialContext creates a new instance of Manager connected to the server at address ctx is used to create derived contexts for a variety of long-running operations.

# Variables

ErrBlacklistedEvent is returned when an attempt is made to Emit a reserved event from a Socket.
ErrInvalidAddress is returned when the user-supplied address is invalid.

# Structs

Manager manages Socket.IO connections to a single server across multiple namespaces.
ManagerConfig contains configuration information for a Manager.
Socket sends messages to and receive messages from a Socket.IO Namespace https://socket.io/docs/rooms-and-namespaces/.

# Type aliases

AckFunc is a func that can be called in response to receiving an ACK packet.