Commit 4b2f94d8 authored by haoyanbin's avatar haoyanbin

1

parent 1771807e
......@@ -12,10 +12,10 @@ import (
"time"
)
var addr = flag.String("addr", "localhost:8080", "http service address")
var addr = flag.String("addr", "39.96.85.45:11001", "http service address")
func main() {
go WsClient("1001_1_2")
go WsClient("1_system_3_1")
select {}
}
......@@ -72,7 +72,7 @@ func WsClient(id string) {
select {
case <-done:
//重新连接
go wsClient(id)
go WsClient(id)
return
case <-ticker.C:
msg := &pool.SendMsg{
......
......@@ -15,11 +15,11 @@ const (
pongWait = 60 * time.Second
// Send pings to peer with this period. Must be less than pongWait.
pingPeriod = (pongWait * 9) / 10 //1 * time.Second//(pongWait * 9) / 10
//var pingPeriod =27* time.Second //1 * time.Second//(pongWait * 9) / 10
pingPeriod = (pongWait * 9) / 10
// Time allowed to write a message to the peer.
writeWait = 30 * time.Second
writeWait = 10 * time.Second
// Maximum message size allowed from peer.
maxMessageSize = 1024 * 1024 * 20
......@@ -313,6 +313,7 @@ Loop:
if p == 1 {
c.conn.SetWriteDeadline(time.Now().Add(writeWait))
if err := c.conn.WriteMessage(websocket.PingMessage, nil); err != nil {
fmt.Println(err)
c.onError(errors.New("连接ID:" + c.Id + "关闭写入IO对象出错,连接中断" + err.Error()))
goto Loop1
}
......@@ -324,6 +325,7 @@ Loop:
if p == 1 {
c.conn.SetWriteDeadline(time.Now().Add(writeWait))
if err := c.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
fmt.Println(err)
c.onError(errors.New("回复客户端PongMessage出现异常:" + err.Error()))
goto Loop1
}
......
......@@ -87,7 +87,7 @@ func (c *Client) OpenClient(w http.ResponseWriter, r *http.Request, head http.He
c.closeTicker = time.NewTimer(closeWait)
c.conn.SetPongHandler(func(str string) error {
c.conn.SetReadDeadline(time.Now().Add(pongWait))
//fmt.Println("收到pong---", c.Id, str)
fmt.Println("收到pong---", c.Id, str)
c.pingPeriodTicker.Reset(pingPeriod)
c.onPong()
return nil
......@@ -96,7 +96,7 @@ func (c *Client) OpenClient(w http.ResponseWriter, r *http.Request, head http.He
c.conn.SetPingHandler(func(str string) error {
c.conn.SetReadDeadline(time.Now().Add(pongWait))
c.pingPeriodTicker.Reset(pingPeriod)
//fmt.Println("收到ping---", c.Id, str)
fmt.Println("收到ping---", c.Id, str)
c.recvPing <- 1
//if err := c.conn.WriteMessage(websocket.PongMessage, nil); err != nil {
// c.onError(errors.New("回复客户端PongMessage出现异常:"+err.Error()))
......@@ -239,7 +239,7 @@ func (c *Client) Close() {
// 在此方法中sendMsg.Channel指定的值不会处理
func Send(msg *SendMsg) error {
//log.Info("发送指令:",msg.Cmd,msg.ToClientId)
//fmt.Println(msg)
fmt.Println(msg)
if msg.ToClientId == "" {
return errors.New("发送消息的消息体中未指定ToClient目标!")
}
......@@ -465,6 +465,16 @@ func AppendConversation(conversation *Conversation) {
return
}
func DelConversationRecord(conversationId int) {
Redis.HDel(convKey, strconv.Itoa(conversationId))
return
}
func AppendConversationRecord(conversation *SendMsg) {
Redis.HSetNX(convKey+":"+strconv.Itoa(conversation.ConversationId), strconv.Itoa(conversation.ConversationId), string(SerializeJson(conversation)))
return
}
func DelConversation(conversationId int) {
Redis.HDel(convKey, strconv.Itoa(conversationId))
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment