Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
im-pool
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoyanbin
im-pool
Commits
4b2f94d8
Commit
4b2f94d8
authored
Dec 05, 2022
by
haoyanbin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
1771807e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
9 deletions
+21
-9
client.go
client.go
+3
-3
client.go
pool/client.go
+5
-3
publicApi.go
pool/publicApi.go
+13
-3
No files found.
client.go
View file @
4b2f94d8
...
...
@@ -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
(
"1
001_1_2
"
)
go
WsClient
(
"1
_system_3_1
"
)
select
{}
}
...
...
@@ -72,7 +72,7 @@ func WsClient(id string) {
select
{
case
<-
done
:
//重新连接
go
w
sClient
(
id
)
go
W
sClient
(
id
)
return
case
<-
ticker
.
C
:
msg
:=
&
pool
.
SendMsg
{
...
...
pool/client.go
View file @
4b2f94d8
...
...
@@ -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
}
...
...
pool/publicApi.go
View file @
4b2f94d8
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment