Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
togettoyou committed Feb 5, 2021
1 parent 85b3c9c commit 5093dc9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,33 @@ $ go get -v github.com/togettoyou/wsc
#### Simple example

``` go
package main

import (
"github.com/togettoyou/wsc"
"log"
"time"
)

func main() {
done := make(chan bool)
ws := wsc.New("ws://127.0.0.1:7777/ws")
// 自定义配置,不使用默认配置
ws.SetConfig(&wsc.Config{
WriteWait: 10 * time.Second,
MaxMessageSize: 2048,
MinRecTime: 2 * time.Second,
MaxRecTime: 60 * time.Second,
RecFactor: 1.5,
MessageBufferSize: 1024,
})
// 回调处理
// 可自定义配置,不使用默认配置
//ws.SetConfig(&wsc.Config{
// // 写超时
// WriteWait: 10 * time.Second,
// // 支持接受的消息最大长度,默认512字节
// MaxMessageSize: 2048,
// // 最小重连时间间隔
// MinRecTime: 2 * time.Second,
// // 最大重连时间间隔
// MaxRecTime: 60 * time.Second,
// // 每次重连失败继续重连的时间间隔递增的乘数因子,递增到最大重连时间间隔为止
// RecFactor: 1.5,
// // 消息发送缓冲池大小,默认256
// MessageBufferSize: 1024,
//})
// 设置回调处理
ws.OnConnected(func() {
log.Println("OnConnected: ", ws.WebSocket.Url)
// 连接成功后,测试每5秒发送消息
Expand Down
26 changes: 16 additions & 10 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ import (
func main() {
done := make(chan bool)
ws := wsc.New("ws://127.0.0.1:7777/ws")
// 自定义配置,不使用默认配置
ws.SetConfig(&wsc.Config{
WriteWait: 10 * time.Second,
MaxMessageSize: 2048,
MinRecTime: 2 * time.Second,
MaxRecTime: 60 * time.Second,
RecFactor: 1.5,
MessageBufferSize: 1024,
})
// 回调处理
// 可自定义配置,不使用默认配置
//ws.SetConfig(&wsc.Config{
// // 写超时
// WriteWait: 10 * time.Second,
// // 支持接受的消息最大长度,默认512字节
// MaxMessageSize: 2048,
// // 最小重连时间间隔
// MinRecTime: 2 * time.Second,
// // 最大重连时间间隔
// MaxRecTime: 60 * time.Second,
// // 每次重连失败继续重连的时间间隔递增的乘数因子,递增到最大重连时间间隔为止
// RecFactor: 1.5,
// // 消息发送缓冲池大小,默认256
// MessageBufferSize: 1024,
//})
// 设置回调处理
ws.OnConnected(func() {
log.Println("OnConnected: ", ws.WebSocket.Url)
// 连接成功后,测试每5秒发送消息
Expand Down

0 comments on commit 5093dc9

Please sign in to comment.