socket.io library for golang, a realtime application framework.

Related tags

go-socket.io
Overview

go-socket.io

GoDoc Build Status Coverage Status Go Report Card

go-socket.io is library an implementation of Socket.IO in Golang, which is a realtime application framework.

Current this library supports 1.4 version of the Socket.IO client. It supports room, namespaces and broadcast at now.

Help wanted This project is looking for contributors to help fix bugs and implement new features. Please check Issue 192. All help is much appreciated.

Contents

Install

Install the package with:

go get github.com/googollee/go-socket.io

Import it with:

import "github.com/googollee/go-socket.io"

and use socketio as the package name inside the code.

Example

Please check more examples into folder in project for details. Examples

FAQ

It is some popular questions about this repository:

  • Is this library supported socket.io version 2?
    • No, but if you wanna you can help to do it. Join us in community chat Telegram
  • How to use go-socket.io with CORS?
  • What is minimal version Golang support for this library?
    • We required Go 1.9 or upper!
  • How to user?
    • Go-socket.io compatibility with Socket.IO 0.9.x, please use branch 0.9.x * or tag [email protected]

Community

Telegram chat: @go_socketio

Engineio

This project contains a sub-package called engineio. This used to be a separate package under https://github.com/googollee/go-engine.io.

It contains the engine.io analog implementation of the original node-package. https://github.com/socketio/engine.io It can be used without the socket.io-implementation. Please check the README.md in engineio/.

License

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

Issues
  • Client doesn't work with Node.js socket.io server

    Client doesn't work with Node.js socket.io server

    Using the socket.io client example, run against the node.js socket.io server example doesn't work. It appears as :

    panic: invalid status: 400 Bad Request
    
    goroutine 1 [running]:
    runtime.panic(0x642720, 0xc21000a820)
            /usr/lib/go/src/pkg/runtime/panic.c:266 +0xb6
    main.main()
            /home/david/Development/gowork/src/socketclient.go:25 +0x74
    
    goroutine 4 [syscall]:
    runtime.goexit()
            /usr/lib/go/src/pkg/runtime/proc.c:1394
    
    goroutine 5 [runnable]:
    net/http.(*persistConn).readLoop(0xc21005b400)
            /usr/lib/go/src/pkg/net/http/transport.go:778 +0x68f
    created by net/http.(*Transport).dialConn
            /usr/lib/go/src/pkg/net/http/transport.go:528 +0x607
    
    goroutine 6 [select]:
    net/http.(*persistConn).writeLoop(0xc21005b400)
            /usr/lib/go/src/pkg/net/http/transport.go:791 +0x271
    created by net/http.(*Transport).dialConn
            /usr/lib/go/src/pkg/net/http/transport.go:529 +0x61e
    

    The server returns a 400 error with the response message 'transport:undefined'

    The equivalent node.js client seems to connect to the socket.io url with an additional transport param set to 'polling', and then goes through a protocol upgrade to websockets.

    Is a node server/ go client expected to work?

    question 
    opened by daviddawson 24
  • disconnection event has not emit

    disconnection event has not emit

    use the demo file main.go refresh the browser,the log is:

    2014/08/17 17:40:03 main.go:17: on connection
    2014/08/17 17:40:06 main.go:17: on connection
    2014/08/17 17:40:07 main.go:17: on connection
    2014/08/17 17:40:09 main.go:17: on connection
    
    opened by hidu 23
  • example in documentation  report

    example in documentation report "http: multiple response.WriteHeader calls" error when client connect from browser. And the client received "Error during WebSocket handshake Ask Unexpected response code: 403"

    Hi, guys, I tried your example in branch 1.4, i write a simplest web page to conncet the example main.go server, first i received cors error, after fix that , then the server print out some log "http: multiple response.WriteHeader calls" and the client also report the error : "Error during WebSocket handshake Ask Unexpected response code: 403", do someone see this problem before?

    question documentation might-be-cors-issue 
    opened by mmmmmagina 23
  • Writing data more frequently will cause panic

    Writing data more frequently will cause panic

    发现如果数据发送的比较频繁,会导致与ping的数据写时并发,go race 在大量的客户端的情况下,会引起websocket的写并发panic。

    bug 
    opened by pangdahua 20
  • http: response.WriteHeader on hijacked connection using websocket transport

    http: response.WriteHeader on hijacked connection using websocket transport

    Hi! Thanks for a library. I have faced a strange problem using it and cannot fix it by myself

    Here is a simple reproduce case:

    package main
    
    import (
        "log"
        "net/http"
    
        "github.com/googollee/go-socket.io"
    )
    
    func main() {
        server, err := socketio.NewServer(nil)
        if err != nil {
            log.Fatal(err)
        }
        server.On("connection", func(so socketio.Socket) {
            log.Println("on connection")
            so.Join("chat")
            so.On("chat message", func(msg string) {
                log.Println("emit:", so.Emit("chat message", msg))
                so.BroadcastTo("chat", "chat message", msg)
            })
            so.On("disconnection", func() {
                log.Println("on disconnect")
            })
        })
        server.On("error", func(so socketio.Socket, err error) {
            log.Println("error:", err)
        })
    
        http.Handle("/socket.io/", server)
        http.Handle("/", http.FileServer(http.Dir("./asset")))
        log.Println("Serving at localhost:5000...")
        log.Fatal(http.ListenAndServe(":5000", nil))
    }
    

    and in the browser I use something like

    <!doctype html>
    <html>
    <head>
        <title>Socket.IO chat</title>
    </head>
    <body>
    <script src="socket.io.js"></script>
    <script>
        var socket = io('localhost:5000', {transports: ["websocket"]})
        console.log(socket)
    </script>
    </body>
    </html>
    

    Then I see strange warnings in my applications's log:

    2015/11/21 20:43:30 Serving at localhost:5000...
    2015/11/21 20:43:35 http: response.WriteHeader on hijacked connection
    2015/11/21 20:43:35 on connection
    

    Using gdb I have found that the problem is that we are still serving http on hijacked connection.

    2015/11/21 20:46:17 Serving at localhost:5000...
    
    Breakpoint 1, net/http.(*response).WriteHeader (w=0xc8200b3810, code=400) at /usr/lib/go/src/net/http/server.go:683
    683         w.conn.server.logf("http: response.WriteHeader on hijacked connection")
    (gdb) bt
    #0  net/http.(*response).WriteHeader (w=0xc8200b3810, code=400) at /usr/lib/go/src/net/http/server.go:683
    #1  0x000000000065db00 in github.com/googollee/go-engine.io/websocket.(*Server).ServeHTTP (s=0xc82000e960, w=..., 
        r=0xc8200d2000) at /root/gopath/src/github.com/googollee/go-engine.io/websocket/server.go:35
    #2  0x00000000005d8cb9 in github.com/googollee/go-engine%2eio.(*serverConn).ServeHTTP (c=0xc820057d40, w=..., r=0xc8200d2000)
        at /root/gopath/src/github.com/googollee/go-engine.io/server_conn.go:197
    #3  0x00000000005d717d in github.com/googollee/go-engine%2eio.(*Server).ServeHTTP (s=0xc8200160e0, w=..., r=0xc8200d2000)
        at /root/gopath/src/github.com/googollee/go-engine.io/server.go:159
    #4  0x00000000004a5783 in github.com/googollee/go-socket%2eio.(*Server).ServeHTTP (s=0xc82000e660, w=..., r=0xc8200d2000)
        at /root/gopath/src/github.com/googollee/go-socket.io/server.go:87
    #5  0x000000000047d16d in net/http.(*ServeMux).ServeHTTP (mux=0xc820010960, w=..., r=0xc8200d2000)
        at /usr/lib/go/src/net/http/server.go:1699
    #6  0x000000000047dbde in net/http.serverHandler.ServeHTTP (sh=..., rw=..., req=0xc8200d2000)
        at /usr/lib/go/src/net/http/server.go:1862
    #7  0x000000000047b3ce in net/http.(*conn).serve (c=0xc8200b3550) at /usr/lib/go/src/net/http/server.go:1361
    #8  0x000000000045bd01 in runtime.goexit () at /usr/lib/go/src/runtime/asm_amd64.s:1696
    #9  0x000000c8200b3550 in ?? ()
    #10 0x0000000000000000 in ?? ()
    

    But I am not familiar with websockets and your implementation to go further.

    Is it my mistake somewhere or bug in library? Thank you

    opened by bo0rsh201 16
  • support cluster?

    support cluster?

    can support cluster?

    duplicate 
    opened by arden 16
  • Merge engine.io into socket.io

    Merge engine.io into socket.io

    Discussion at #296

    v2 
    opened by adrianmxb 13
  • Client API

    Client API

    Currently there is only the Server API. Are there any plans to add a client as well?

    opened by fd 13
  • I'm getting bad request

    I'm getting bad request

    When emitting events from client, I got Bad Request

    POST http://localhost:8500/socket.io/?EIO=3&transport=polling&t=1578039627529-2&sid=4 400 (Bad Request)

    And on the server console, it said 'resume'

    Here's my client code:

    var socket = io();
    
    var mesageForm = document.getElementById('send-container');
    var mesageContainer = document.getElementById('message-container');
    var mesageInput = document.getElementById('message-input');
    
    
    const name = prompt('What is your name?');
    appendMessage('You' + ' joined');
    
    socket.emit('new-user', name);
    
    socket.on('chat-message', data => {
        appendMessage(data)
    });
    
    socket.on('user-connected', name => {
        appendMessage(name + ' joined')
    });
    
    mesageForm.addEventListener('submit', function (e) {
        e.preventDefault();
    
        const message = mesageInput.value;
        socket.emit('send-chat-message', message);
        mesageInput.value = ''
    });
    
    function appendMessage(msg) {
        const messageElement = document.createElement('div');
    
        messageElement.innerText = msg;
        mesageContainer.append(messageElement)
    }
    

    And here's my server code

    package main
    
    import (
    	socketio "github.com/googollee/go-socket.io"
    	"github.com/labstack/echo"
    )
    
    type Sock struct {
    	sock socketio.Conn
    	Name string
    }
    
    var socks = make(map[string]Sock)
    
    func main() {
    	io, _ := socketio.NewServer(nil)
    	
    	app := echo.New()
    	
    	app.Static("/", ".")
    	
    	app.Any("/socket.io/", func(s echo.Context) error {
    		io.ServeHTTP(s.Response().Writer, s.Request())
    		
    		return nil
    	})
    	
    	io.OnConnect("/", func(s socketio.Conn) error {
    		socks[s.ID()] = Sock{
    			sock: s,
    		}
    		
    		s.Emit("chat-message", "Server: Hello World")
    		
    		return nil
    	})
    	
    	io.OnEvent("/", "new-user", func(s socketio.Conn, name string) {
    		sk := socks[s.ID()]
    		sk.Name = name
    		
    		for k, v := range socks {
    			if k != s.ID() {
    				v.sock.Emit("user-connected", name)
    			}
    		}
    	})
    	
    	io.OnEvent("/", "send-chat-message", func(s socketio.Conn, msg string) {
    		for k, v := range socks {
    			if k != s.ID() {
    				v.sock.Emit("chat-message", msg)
    			}
    		}
    	})
    	
    	go io.Serve()
    	defer io.Close()
    	
    	app.Start(":8500")
    }
    

    It's annoying. What is causing this error?

    might-be-cors-issue 
    opened by cyantarek 13
  • I getting unexpected and unexplained message while running the socket

    I getting unexpected and unexplained message while running the socket

    Describe the bug I'm getting the bellow message and not sure why its coming and how to solve it "Did you forget to Close() the ReadCloser from NextReader?"

    To Reproduce Run a socket connection with multiple clients which keep sending message

    Expected behavior should explain where this problem is happening and logs or point towards how to solve it

    Environment (please complete the following information):

    • Go version: 1.13
    • Server version v1.4.3
    • Client version v2.3.0

    Additional context "Did you forget to Close() the ReadCloser from NextReader?"

    bug 
    opened by Albinzr 12
  • disconnect event sometimes not called

    disconnect event sometimes not called

    Describe the bug

    sometimes,a client has already dead,but disconnect event was not been called

    bug 
    opened by suxianbaozi 0
  • is go-socket.io compatible with GoFiber

    is go-socket.io compatible with GoFiber

    I am using Gofiber. But I cannot understand how to use Socket.io in Gofiber. Is it possible to use Socket.io with GoFiber?

    opened by shahriar350 0
  • session remove the SID when close

    session remove the SID when close

    null

    opened by jiangjinyuan 1
  • sessionManager.Remove(sid) never called

    sessionManager.Remove(sid) never called

    The internal Remove(sid) function seems to never be called which causes the number of connections to keep rising

    This is easily testable by connecting/disconnecting to the server and querying the server.Count() method to see the number keep rising

    bug 
    opened by morapelker 1
  • How to solve 403 error while using go-gin

    How to solve 403 error while using go-gin

    Hello I'm facing issues with gin. I tried using CORS middleware, but it shows 403 error here is my router and server := socketio.NewServer(nil)

    h.SocketService := *server

    router.GET("/socket.io/*any", gin.WrapH(h.SocketService)) router.POST("/socket.io/*any", gin.WrapH(h.SocketService))

    opened by rajatvyadav 1
  • socket client

    socket client

    hi guys i saw it supports scoket client 1.4 which is the version extraheaders were added but it is not working i am using the latest verion of go_websocket.io 1.6?

    opened by LibenHailu 1
  • Decoder for the polling transport.

    Decoder for the polling transport.

    null

    opened by googollee 0
  • how to test go_socket???

    how to test go_socket???

    testing sample please?? i dont know how i to test it??

    opened by LibenHailu 0
  • How to connect redis adaptor for test local server send message and cloud server can get the message?

    How to connect redis adaptor for test local server send message and cloud server can get the message?

    serverredisconfig I'm config redis adaptor for test about localhost send message across to server connect testsendmessageredis I'm test send message on the localhost but on the server isn't get a message. How to solve it? 1629213806834@2x I'm read the socket io document.It can send

    question 
    opened by surapong-thom 0
  • getting request for authentication?

    getting request for authentication?

    how can i get the original request handshake in tag v.1.6 socketio.conn.RemoteHeader() sends only the header but i want the hole handshake request response l a response like socket.Request() in 1.4.0?

    question 
    opened by LibenHailu 1
Releases(v1.6.1)
Owner
Googol Lee
Googol Lee
socket.io library for golang, a realtime application framework.

go-socket.io go-socket.io is library an implementation of Socket.IO in Golang, which is a realtime application framework. Current this library support

Googol Lee 4.3k Oct 24, 2021
Go client library SDK for Ably realtime messaging service

Ably Go A Go client library for www.ably.io, the realtime messaging service. Installation ~ $ go get -u github.com/ably/ably-go/ably Feature support T

Ably Realtime - our client library SDKs and libraries 34 Oct 16, 2021
💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps.

Beaver A Real Time Messaging Server. Beaver is a real-time messaging server. With beaver you can easily build scalable in-app notifications, realtime

Ahmed 1.3k Oct 24, 2021
goczmq is a golang wrapper for CZMQ.

goczmq Introduction A golang interface to the CZMQ v4.2 API. Install Dependencies libsodium libzmq czmq For CZMQ master go get github.com/zeromq/goczm

The ZeroMQ project 468 Oct 14, 2021
Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery Machinery is an asynchronous task queue/job queue based on distributed message passing. V2 Experiment First Steps Configuration Lock Broker

Richard Knop 5.6k Oct 14, 2021
A Go interface to ZeroMQ version 2

A Go interface to ZeroMQ version 2. Requires ZeroMQ version 2.1 or 2.2 For ZeroMQ version 4, see: http://github.com/pebbe/zmq4 For ZeroMQ version 3, s

Peter Kleiweg 18 May 26, 2021
Server-sent live updates: protocol and reference implementation

Protocol and Reference Implementation Mercure is a protocol allowing to push data updates to web browsers and other HTTP clients in a convenient, fast

Kévin Dunglas 2.6k Oct 24, 2021
A realtime distributed messaging platform

Source: https://github.com/nsqio/nsq Issues: https://github.com/nsqio/nsq/issues Mailing List: [email protected] IRC: #nsq on freenode Docs:

NSQ 20.4k Oct 22, 2021
GTA(Go Task Async) is a lightweight reliable asynchronous task and transaction message library for Golang

GTA (Go Task Async) is a lightweight and reliable asynchronous task and transaction message library for by golang.

Kevin Su 6 Jul 15, 2021
🐇 Easy to use socket lib for Golang

Hare Sockets ?? Hare is a user-friendly lib for sockets in Golang. You can send and listen to TCP connections with a few lines of code. Contents Insta

Leonardo Lima 30 Sep 21, 2021
A user friendly RabbitMQ library written in Golang.

TurboCookedRabbit A user friendly RabbitMQ library written in Golang to help use streadway/amqp. Based on my work found at CookedRabbit. Work Recently

Tristan (HouseCat) Hyams 90 Oct 11, 2021
A push notification server written in Go (Golang).

gorush A push notification micro server using Gin framework written in Go (Golang) and see the demo app. Contents gorush Contents Support Platform Fea

Bo-Yi Wu 5.8k Oct 21, 2021
websocket based messaging server written in golang

Guble Messaging Server Guble is a simple user-facing messaging and data replication server written in Go. Overview Guble is in an early state (release

Sebastian Mancke 148 Sep 7, 2021
Open source Observability Platform. 👉 SigNoz helps developers find issues in their deployed applications & solve them quickly

SigNoz SigNoz is an opensource observability platform. SigNoz uses distributed tracing to gain visibility into your systems and powers data using Kafk

SigNoz 4.9k Oct 24, 2021
:notes: Minimalist websocket framework for Go

melody ?? Minimalist websocket framework for Go. Melody is websocket framework based on github.com/gorilla/websocket that abstracts away the tedious p

Ola 2.3k Oct 17, 2021
NSQ as backend for Queue Package

NSQ as backend for Queue Package

golang-queue 6 Sep 19, 2021
RES Service protocol library for Go

RES Service for Go Synchronize Your Clients Go package used to create REST, real time, and RPC APIs, where all your reactive web clients are synchroni

Samuel Jirénius 51 Oct 12, 2021
Implementation of the NELI leader election protocol for Go and Kafka

goNELI Implementation of the NELI leader election protocol for Go and Kafka. goNELI encapsulates the 'fast' variation of the protocol, running in excl

Obsidian Dynamics 52 Oct 12, 2021
Confluent's Apache Kafka Golang client

Confluent's Golang Client for Apache KafkaTM confluent-kafka-go is Confluent's Golang client for Apache Kafka and the Confluent Platform. Features: Hi

Confluent Inc. 3k Oct 22, 2021