You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I now have a client for node.js implementation.code show as below:
`var url = require('url'),
util = require('util'),
server_url = url.parse('127.0.0.1:8080'),
socket = require('socket.io-client')(url.format({
protocol: server_url.protocol,
hostname: server_url.hostname,
port: server_url.port,
pathname: 'test.io',
query: {
identify: 'Data',
key: 'b290e8b3f35343ac9d275265'
}
}));
socket.on('connect', function () {
util.log('plpc.io connected');
var buf = new Buffer(39);
socket.emit('test-msg', buf);
}I am writing the client with graarh/golang-socketio, the code is as follows:var Url string
//Url = "ws://192.0.0.1:8080/socket.io/plpc.io?EIO=3&identify=Data&key=b290e8b3f35343ac9d275265&transport=websocket"
The current situation is that the client written by node.js can work normally. The client written by golang can connect to the server, but the server cannot parse the data correctly.I modified two functions in the socket.io-client library.
`/**
Get ws/wss url by host and port
*/
func GetUrl(host string, port int, params []string, secure bool) string {
var prefix string
if secure {
prefix = webSocketSecureProtocol
} else {
prefix = webSocketProtocol
}
//return prefix + host + ":" + strconv.Itoa(port) + socketioUrl
_url, err := url.Parse(prefix + host + ":" + strconv.Itoa(port) + socketioUrl)
if err != nil {
fmt.Println("We unable to parse given url: ", _url)
}
if len(params) > 0 {
_uval := _url.Query()
for _, element := range params {
s := strings.Split(element, "=")
_uval.Add(s[0], s[1])
}
_url.RawQuery = _uval.Encode()
}
return _url.String()
}
/**
connect to host and initialise socket.io protocol
The correct ws protocol url example:
ws://myserver.com/socket.io/?EIO=3&transport=websocket
You can use GetUrlByHost for generating correct url
*/
func Dial(url string, nsp string, tr transport.Transport) (*Client, error) {
c := &Client{}
c.initChannel()
c.initMethods()
var err error
c.conn, err = tr.Connect(url)
if err != nil {
return nil, err
}
nspMsg := fmt.Sprintf("4%d%s", protocol.MessageTypeOpen, nsp)
c.conn.WriteMessage(nspMsg)
go inLoop(&c.Channel, &c.methods)
go outLoop(&c.Channel, &c.methods)
go pinger(&c.Channel)
return c, nil
}`
why is the client written by GO not working properly? And, what should be the correct way to write?
The text was updated successfully, but these errors were encountered:
I now have a client for node.js implementation.code show as below:
`var url = require('url'),
util = require('util'),
server_url = url.parse('127.0.0.1:8080'),
socket = require('socket.io-client')(url.format({
protocol: server_url.protocol,
hostname: server_url.hostname,
port: server_url.port,
pathname: 'test.io',
query: {
identify: 'Data',
key: 'b290e8b3f35343ac9d275265'
}
}));
socket.on('connect', function () {
util.log('plpc.io connected');
var buf = new Buffer(39);
socket.emit('test-msg', buf);
}
I am writing the client with graarh/golang-socketio, the code is as follows:
var Url string//Url = "ws://192.0.0.1:8080/socket.io/plpc.io?EIO=3&identify=Data&key=b290e8b3f35343ac9d275265&transport=websocket"
The current situation is that the client written by node.js can work normally. The client written by golang can connect to the server, but the server cannot parse the data correctly.I modified two functions in the socket.io-client library.
`/**
Get ws/wss url by host and port
*/
func GetUrl(host string, port int, params []string, secure bool) string {
var prefix string
if secure {
prefix = webSocketSecureProtocol
} else {
prefix = webSocketProtocol
}
//return prefix + host + ":" + strconv.Itoa(port) + socketioUrl
_url, err := url.Parse(prefix + host + ":" + strconv.Itoa(port) + socketioUrl)
if err != nil {
fmt.Println("We unable to parse given url: ", _url)
}
}
/**
connect to host and initialise socket.io protocol
The correct ws protocol url example:
ws://myserver.com/socket.io/?EIO=3&transport=websocket
You can use GetUrlByHost for generating correct url
*/
func Dial(url string, nsp string, tr transport.Transport) (*Client, error) {
c := &Client{}
c.initChannel()
c.initMethods()
}`
why is the client written by GO not working properly? And, what should be the correct way to write?
The text was updated successfully, but these errors were encountered: