package module
v0.0.0-...-83ee737 Latest Latest

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

Go to latest
Published: Sep 25, 2020 License: BSD-3-Clause Imports: 20 Imported by: 46

README is an client implementation of in golang, which is a realtime application framework.

It is compatible with latest implementation of in node.js, and supports namespace.


Install the package with:

go get

Import it with:

import ""

and use socketio_client as the package name inside the code.


Please check the example folder for details.

package main

import (

func main() {

	opts := &socketio_client.Options{
		Transport: "websocket",
		Query:     make(map[string]string),
	opts.Query["user"] = "user"
	opts.Query["pwd"] = "pass"
	uri := ""

	client, err := socketio_client.NewClient(uri, opts)
	if err != nil {
		log.Printf("NewClient error:%v\n", err)

	client.On("error", func() {
		log.Printf("on error\n")
	client.On("connection", func() {
		log.Printf("on connect\n")
	client.On("message", func(msg string) {
		log.Printf("on message:%v\n", msg)
	client.On("disconnection", func() {
		log.Printf("on disconnect\n")

	reader := bufio.NewReader(os.Stdin)
	for {
		data, _, _ := reader.ReadLine()
		command := string(data)
		client.Emit("message", command)
		log.Printf("send message:%v\n", command)


The 3-clause BSD License - see LICENSE for more details




View Source
const Protocol = 4


View Source
var InvalidError = errors.New("invalid transport")


This section is empty.


type Attachment

type Attachment struct {

	// Data is the ReadWriter of the attachment data.
	Data io.ReadWriter
	// contains filtered or unexported fields

Attachment is an attachment handler used in emit args. All attachments will send as binary in transport layer. When use attachment, make sure use as pointer.

For example:

type Arg struct {
    Title string `json:"title"`
    File *Attachment `json:"file"`

f, _ := os.Open("./some_file")
arg := Arg{
    Title: "some_file",
    File: &Attachment{
        Data: f,

socket.Emit("send file", arg)
socket.On("get file", func(so Socket, arg Arg) {
    b, _ := ioutil.ReadAll(arg.File.Data)

func (Attachment) MarshalJSON

func (a Attachment) MarshalJSON() ([]byte, error)

func (*Attachment) UnmarshalJSON

func (a *Attachment) UnmarshalJSON(b []byte) error

type Client

type Client struct {
	// contains filtered or unexported fields

func NewClient

func NewClient(uri string, opts *Options) (client *Client, err error)

func (*Client) Emit

func (client *Client) Emit(message string, args ...interface{}) (err error)

func (*Client) On

func (client *Client) On(message string, f interface{}) (err error)

type MessageType

type MessageType message.MessageType

type Options

type Options struct {
	Transport string            //protocol name string,websocket polling...
	Query     map[string]string //url的附加的参数
	Header    map[string][]string


Path Synopsis

Jump to

Keyboard shortcuts

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