1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| package main
import ( "fmt" "github.com/gorilla/websocket" "google.golang.org/protobuf/proto" "log" "os" "os/signal" "proto3TestClient/testproto" )
type JsonEntity struct { BillID string `json:"billID"` BookId string `json:"bookId"` Money int `json:"money"` CrtUser string `json:"crtUser"` Time int `json:"time"` Category string `json:"category"` Type int `json:"type"` Remark string `json:"remark"` }
func main() { serverAddr := "ws://localhost:8080/ws"
conn, _, err := websocket.DefaultDialer.Dial(serverAddr, nil) if err != nil { log.Fatal("Error connecting to WebSocket:", err) } defer conn.Close()
interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) var wsMsgList []*testproto.WsMsg singleWsMsg := &testproto.WsMsg{ Id: "123456789a", Type: testproto.Types_ADD_BILL, Timestamp: 1232133221313321321, FromId: "hao88.cloud", ToId: "a,b,c,d,e,f", } wsMsgList = append(wsMsgList, singleWsMsg) message := testproto.AddBill{ WsMsg: wsMsgList, BillID: "BillID12345", BookId: "BookId67890", Money: 100, CrtUser: "John Doe", Time: 1638460800, Category: "Expense", Type: 1, Remark: "Example remark", }
messageBytes, err := proto.Marshal(&message) if err != nil { log.Fatal("Error marshaling Proto3 message:", err) } var count = 0
for count < 10000 { err = conn.WriteMessage(websocket.BinaryMessage, messageBytes) if err != nil { log.Fatal("Error writing Proto3 message:", err) } count++ fmt.Printf("send count =%d \n", count) } }
|