优化
This commit is contained in:
parent
2049a50745
commit
a119a37aa9
@ -8,8 +8,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
// zlog "go_dreamfactory/lego/sys/log"
|
|
||||||
|
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@ -170,63 +168,37 @@ func (r *RobotFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|||||||
return b.Bytes(), nil
|
return b.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Robot) ExecSendMsg(mainType, subType string, msg proto.Message) {
|
func (r *Robot) MessageRsp(mainType, subType string) bool {
|
||||||
|
|
||||||
if msg != nil {
|
|
||||||
head := &pb.UserMessage{MainType: mainType, SubType: subType}
|
|
||||||
err := r.SendToClient(head, msg)
|
|
||||||
if err != nil {
|
|
||||||
zlog.Errorf("send to client err:%v", err)
|
|
||||||
}
|
|
||||||
r.messageRsp(mainType, subType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Robot) MessageRsp() {
|
|
||||||
|
|
||||||
var msg *pb.UserMessage = &pb.UserMessage{}
|
var msg *pb.UserMessage = &pb.UserMessage{}
|
||||||
_, data, err := r.ws.ReadMessage()
|
_, data, err := r.ws.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zlog.Fatalf("readMessage err:%v", err)
|
fmt.Printf("readMessage err:%v", err)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = proto.Unmarshal(data, msg); err != nil {
|
if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
zlog.Fatalf("unmarshal err:%v", err)
|
fmt.Printf("unmarshal err:%v", err)
|
||||||
}
|
}
|
||||||
|
//fmt.Printf("接收消息=====msg.MainType = %s,msg.SubType = %s\n", msg.MainType, msg.SubType)
|
||||||
if msg.MainType == "chat" && msg.SubType == "message" {
|
if msg.MainType == "chat" && msg.SubType == "message" {
|
||||||
resp := &pb.ChatMessagePush{}
|
resp := &pb.ChatMessagePush{}
|
||||||
if !comm.ProtoUnmarshal(msg, resp) {
|
if !comm.ProtoUnmarshal(msg, resp) {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
zlog.Fatalf("接收消息=====resp:%v", resp.Chat)
|
return false
|
||||||
|
//fmt.Printf("接收消息=====resp:%v\n", resp.Chat)
|
||||||
|
} else if msg.MainType == mainType && msg.SubType == subType {
|
||||||
|
resp := &pb.UserLoginResp{}
|
||||||
|
if !comm.ProtoUnmarshal(msg, resp) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
//fmt.Printf("接收消息=====loginData:%v,userExpand:%v\n", resp.Data, resp.Ex)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
func (r *Robot) messageRsp(mainType, subType string) {
|
|
||||||
|
|
||||||
var msg *pb.UserMessage = &pb.UserMessage{}
|
|
||||||
_, data, err := r.ws.ReadMessage()
|
|
||||||
if err != nil {
|
|
||||||
zlog.Fatalf("readMessage err:%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = proto.Unmarshal(data, msg); err != nil {
|
|
||||||
zlog.Fatalf("unmarshal err:%v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.MainType == mainType &&
|
|
||||||
msg.SubType == subType {
|
|
||||||
rsp := &pb.UserLoginResp{}
|
|
||||||
if !comm.ProtoUnmarshal(msg, rsp) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if msg.MainType == "user" && msg.SubType == "login" {
|
|
||||||
r.loginCallback(rsp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
func (r *Robot) CloseHandler() {
|
func (r *Robot) CloseHandler() {
|
||||||
|
|
||||||
r.ws.Close()
|
r.ws.Close()
|
||||||
|
@ -80,19 +80,13 @@ func webSocketRequest(chanID uint64, ch chan<- *model.RequestResults, i uint64,
|
|||||||
Sid: "dfmxf",
|
Sid: "dfmxf",
|
||||||
}
|
}
|
||||||
r.SendToClient(head, req)
|
r.SendToClient(head, req)
|
||||||
r.MessageRsp()
|
for {
|
||||||
// err := ws.Write([]byte(`{"seq":"` + seq + `","cmd":"ping","data":{}}`))
|
if r.MessageRsp("user", "login") {
|
||||||
// if err != nil {
|
isSucceed = true
|
||||||
// errCode = model.RequestErr // 请求错误
|
break
|
||||||
// } else {
|
}
|
||||||
// msg, err = ws.Read()
|
}
|
||||||
// if err != nil {
|
|
||||||
// errCode = model.ParseError
|
|
||||||
// fmt.Println("读取数据 失败~")
|
|
||||||
// } else {
|
|
||||||
// errCode, isSucceed = request.GetVerifyWebSocket()(request, seq, msg)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
requestTime := uint64(helper.DiffNano(startTime))
|
requestTime := uint64(helper.DiffNano(startTime))
|
||||||
requestResults := &model.RequestResults{
|
requestResults := &model.RequestResults{
|
||||||
Time: requestTime,
|
Time: requestTime,
|
||||||
|
@ -72,8 +72,8 @@ func main() {
|
|||||||
//go run .\main.go -c 10 -n 10 -u ws://10.0.5.101:7891/gateway
|
//go run .\main.go -c 10 -n 10 -u ws://10.0.5.101:7891/gateway
|
||||||
concurrency = 10
|
concurrency = 10
|
||||||
totalNumber = 10
|
totalNumber = 10
|
||||||
debugStr = "true"
|
debugStr = "false"
|
||||||
requestURL = "ws://10.0.5.194:7891/gateway"
|
requestURL = "ws://10.0.0.9:7891/gateway"
|
||||||
if concurrency == 0 || totalNumber == 0 || (requestURL == "" && path == "") {
|
if concurrency == 0 || totalNumber == 0 || (requestURL == "" && path == "") {
|
||||||
fmt.Printf("示例: go run main.go -c 1 -n 1 -u https://www.baidu.com/ \n")
|
fmt.Printf("示例: go run main.go -c 1 -n 1 -u https://www.baidu.com/ \n")
|
||||||
fmt.Printf("压测地址或curl路径必填 \n")
|
fmt.Printf("压测地址或curl路径必填 \n")
|
||||||
|
Loading…
Reference in New Issue
Block a user