1 Star 0 Fork 0

574893508/golang-socketio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
Gennadii Kovalev 提交于 2017-05-10 18:27 . close channel on server side
package gosocketio
import (
"github.com/graarh/golang-socketio/transport"
"strconv"
)
const (
webSocketProtocol = "ws://"
webSocketSecureProtocol = "wss://"
socketioUrl = "/socket.io/?EIO=3&transport=websocket"
)
/**
Socket.io client representation
*/
type Client struct {
methods
Channel
}
/**
Get ws/wss url by host and port
*/
func GetUrl(host string, port int, secure bool) string {
var prefix string
if secure {
prefix = webSocketSecureProtocol
} else {
prefix = webSocketProtocol
}
return prefix + host + ":" + strconv.Itoa(port) + socketioUrl
}
/**
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, 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
}
go inLoop(&c.Channel, &c.methods)
go outLoop(&c.Channel, &c.methods)
go pinger(&c.Channel)
return c, nil
}
/**
Close client connection
*/
func (c *Client) Close() {
closeChannel(&c.Channel, &c.methods)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zyl1221/golang-socketio.git
[email protected]:zyl1221/golang-socketio.git
zyl1221
golang-socketio
golang-socketio
master

搜索帮助