client

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package client is a Go Socket.IO client. It connects to a Socket.IO server (this one or the Node reference server) over the WebSocket transport and provides the familiar On/Emit/EmitWithAck API.

c, err := client.Dial("http://localhost:3000")
c.On("news", func(args []any) []any { fmt.Println(args); return nil })
c.Emit("hello", "world")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a connected Socket.IO client.

func Dial

func Dial(rawURL string, opts ...Options) (*Client, error)

Dial connects to a Socket.IO server at rawURL (http:// or ws://) and returns once the Socket.IO CONNECT handshake completes.

func (*Client) Close

func (c *Client) Close() error

Close disconnects from the server.

func (*Client) Emit

func (c *Client) Emit(event string, args ...any) error

Emit sends an event to the server.

func (*Client) EmitWithAck

func (c *Client) EmitWithAck(event string, timeout time.Duration, args ...any) ([]any, error)

EmitWithAck sends an event and waits for the server's acknowledgement, up to timeout.

func (*Client) ID

func (c *Client) ID() string

ID returns the socket id assigned by the server.

func (*Client) On

func (c *Client) On(event string, h Handler)

On registers a handler for an event.

type Handler

type Handler func(args []any) []any

Handler handles an inbound event. Returning a non-nil slice acknowledges an event the server sent with an ack id.

type Options

type Options struct {
	// Namespace to connect to (default "/").
	Namespace string
	// Auth is an optional payload sent with the CONNECT packet.
	Auth any
	// DialTimeout bounds the connection handshake (default 10s).
	DialTimeout time.Duration
	// Reconnection enables automatic reconnection after an unexpected
	// disconnect.
	Reconnection bool
	// ReconnectionAttempts bounds reconnection tries (0 = unlimited).
	ReconnectionAttempts int
	// ReconnectionDelay is the initial backoff between attempts (default 1s,
	// doubling up to 5s).
	ReconnectionDelay time.Duration
}

Options configures Dial.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL