hesh915 / go-socket.io-client Goto Github PK
View Code? Open in Web Editor NEWsocket.io client for golang
License: BSD 3-Clause "New" or "Revised" License
socket.io client for golang
License: BSD 3-Clause "New" or "Revised" License
Acknowledgements callbacks, eg. when you Emit("myMessage", data, func(s string){...})
were not working for me.
I dug into it and found it is because of Line 148 of client.go, which is currently:
case _ACK:
case _BINARY_ACK:
return nil, client.onAck(packet.Id, decoder, packet)
When an _ACK arrives, client.onAck() is never called.
If I change it to this, it works:
case _ACK:
return nil, client.onAck(packet.Id, decoder, packet)
case _BINARY_ACK:
return nil, client.onAck(packet.Id, decoder, packet)
I'm using Go 1.6.0
Maybe it should be like this?
case _ACK, _BINARY_ACK:
return nil, client.onAck(packet.Id, decoder, packet)
我在实例中没找到如何断开的方法,请大佬指点!
i need keep a stable connection between go client and node server, but after go client read the message this break teh connection.
2019/03/30 17:10:56 on message:hello1553987456281
2019/03/30 17:10:58 on disconnect
how i keep go client connected?
Hello
How are you ?
I have a problem.
I can not use the namespace.
Could you give me an example?
I can access root but not socket room.
Does it work with 0.9.x socketio?
readme中提到支持namespace,请问怎么使用?
opts := &socketio_client.Options{
Transport: "websocket",
Query: make(map[string]string),
}
uri := "https://ws.gate.io/socket.io/"
client, err := socketio_client.NewClient(uri, opts)
if err != nil {
panic(err)
return
}
按照example,用这个地址连接,返回错误invalid input
,我根据源码调试,发现已经获取到了sid等一系列信息。
在client_conn.go文件的325行pack, err = c.getCurrent().NextReader()
返回了错误,有点迷惑
There is a problem with this client that results in connection attempts failing intermittently. This is more easily reproduced by attempting to connect multiple instances of the client to a server.
Here is a gist that has a test to easily reproduce the problem. Just save the file to a directory, make sure you have the required packages, then run go test
to see the failure. It will look very similar to the output below.
These packages are needed to run the tests:
go get -u github.com/googollee/go-socket.io
go get -u github.com/graarh/golang-socketio
go get -u github.com/zhouhui8915/go-socket.io-client
Here is the output of the tests:
>go test
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
2016/11/21 12:10:00 http: response.WriteHeader on hijacked connection
--- FAIL: TestZhouhui (25.00s)
socketio_test.go:74: [server] Listening on 127.0.0.1:58654
socketio_test.go:113: [client] #03 connecting...
socketio_test.go:113: [client] #04 connecting...
socketio_test.go:113: [client] #07 connecting...
socketio_test.go:113: [client] #01 connecting...
socketio_test.go:113: [client] #06 connecting...
socketio_test.go:113: [client] #05 connecting...
socketio_test.go:113: [client] #02 connecting...
socketio_test.go:132: Waiting for client connection attempts to finish
socketio_test.go:113: [client] #10 connecting...
socketio_test.go:113: [client] #08 connecting...
socketio_test.go:113: [client] #09 connecting...
socketio_test.go:65: [server] Client #01 connected: nu8jEhbmI38vzI_i3rUe
socketio_test.go:65: [server] Client #02 connected: iBV0WjWVu1s29p3nJAgE
socketio_test.go:65: [server] Client #03 connected: UeruIAXOHX5ETc8DOpzt
socketio_test.go:65: [server] Client #04 connected: _XcPUDWA0loqGntf0E3w
socketio_test.go:65: [server] Client #05 connected: ySSx04spjsNldmy94c0j
socketio_test.go:65: [server] Client #06 connected: fooWr_iJ2SFQtcQzcMFr
socketio_test.go:65: [server] Client #07 connected: UeruIAXOHX5ETc8DOpzt
socketio_test.go:65: [server] Client #08 connected: 1HIbt6xa3QHb1sJng8be
socketio_test.go:65: [server] Client #09 connected: I0tSRklByiasdszvBgga
socketio_test.go:65: [server] Client #10 connected: WJF5UYjovQzQpHIkf303
socketio_test.go:117: [client] #07 could not connect to http://127.0.0.1:58654: EOF
socketio_test.go:121: [client] #06 connected
socketio_test.go:121: [client] #02 connected
socketio_test.go:121: [client] #04 connected
socketio_test.go:121: [client] #08 connected
socketio_test.go:121: [client] #03 connected
socketio_test.go:121: [client] #05 connected
socketio_test.go:117: [client] #01 could not connect to http://127.0.0.1:58654: EOF
socketio_test.go:117: [client] #10 could not connect to http://127.0.0.1:58654: EOF
socketio_test.go:117: [client] #09 could not connect to http://127.0.0.1:58654: EOF
FAIL
exit status 1
FAIL github.com/dcormier/socket.io-bug 25.072s
The http: response.WriteHeader on hijacked connection
messages are caused by a different issue (googollee/go-socket.io#108) and may appear regardless of whether the connection attempts were successful.
Other socket.io clients work reliably in this same scenario. This one fails.
The error being returned, "EOF", is probably the io.EOF
value. I suspect that the client is expecting data to be immediately available to be read, but in fact it takes a moment for the server to send it. Sometimes the client gets to that point before the server has sent the data.
The failure almost always takes 25 seconds (the default pingInterval
value). There is a second failure that's very rare and returns the same error immediately. I've included notes in the test file on reproducing this one. Very rarely, the test will actually pass. If this happens, just run it again to see it fail.
I'll have to convert my node js socket client connection code that is trying to establish connection with server and also authenticating the user passing auth
params there. My node js client code looks like this. I want the same functionality in golang.
socket = io('localhost:3000', {
path: 'https://localhost:3000/socket.io',
auth: {
username: 'username',
token: "abcd",
},
});
We can pass query params here in this go-socket.io-client implementation, but how can we pass auth
to authenticate the user and achieve the same equivalent functionality as above using this library in go? If it isn't there, kindly add this functionality.
Having this issue in a machine with OSX 10.10.5 and the app was compiled in OSX 10.11.5.
It is working correctly on other machines with OSX 10.9.5, 10.10.3, 10.10.5, 10.11.4, 10.11.5
from github.com/zhouhui8915/engine.io-go/websocket/client.go, func NewClient, "resp" is:
&{Status:400 Bad Request StatusCode:400 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[X-Cache-Lookup:[MISS from m8815449E1B30:3128] Via:[1.1 m8815449E1B30 (squid/3.3.5)] Server:[nginx/1.8.0] Date:[Wed, 18 May 2016 13:49:09 GMT] Content-Type:[application/json] Access-Control-Allow-Origin:[*] X-Cache:[MISS from m8815449E1B30]] Body:{Reader:0xc82087d500} ContentLength:-1 TransferEncoding:[] Close:true Trailer:map[] Request:0xc820668c40 TLS:}
from github.com/zhouhui8915/engine.io-go/websocket/client.go, function NewClient, "err" is:
websocket: bad handshake
here is the content of resp.Body:
{"code":3,"message":"Bad request"}
opts := &socketio_client.Options{
Transport: "websocket",
}
client, err := socketio_client.NewClient("https://cloud.tech", opts)
if err != nil {
log.Printf("NewClient error: %v\n", err)
return
}
client.On("error", func() {
log.Printf("on error\n")
})
I am getting NewClient error: invalid input
你好 我用go-socket.io-client 连接nodejs socket.io 在下面这段代码报错连 原因不明。
p2 := make([]byte, 4096)
l, err = pack.Read(p2)
if err != nil {
return err
}
报错:2019/03/25 16:08:25 NewClient error:EOF
how to send attachment form the frontend how can i do that please help be with sample examples?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.