successfully sent a google protobuf over a gorilla websocket in

a marshal'd binary form. echo protobuf works.

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-11 17:22:14 -07:00
parent 46ee8a456f
commit 36a23911a8
1 changed files with 31 additions and 12 deletions

View File

@ -4,29 +4,39 @@
package main
import (
"flag"
"log"
"net/url"
"os"
"os/signal"
"time"
import "flag"
import "log"
import "net/url"
import "os"
import "os/signal"
import "time"
"github.com/gorilla/websocket"
)
import "github.com/gorilla/websocket"
import "github.com/golang/protobuf/proto"
import pb "git.wit.com/wit/witProtobuf"
// var addr = flag.String("addr", "localhost:8080", "http service address")
var addr = flag.String("addr", "v000185.testing.com.customers.wprod.wit.com:9000", "http service address")
func readConn(done chan struct{}, conn *websocket.Conn) {
defer close(done)
for {
_, message, err := conn.ReadMessage()
mytype, message, err := conn.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
log.Printf("recv: %s", message)
if (mytype == websocket.BinaryMessage) {
pdata := new(pb.Event)
err = proto.Unmarshal(message, pdata)
if (err != nil) {
log.Printf("readConn() something fucked up happened in Unmarshal")
}
log.Printf("recv binary: %s", pdata)
} else {
log.Printf("recv: %s", message)
// log.Printf("type, err = ", mytype, err)
}
}
}
@ -64,6 +74,15 @@ func main() {
log.Println("write:", err)
return
}
msg := pb.CreateSampleEvent()
msg.Name = "test echo over gorilla websocket"
data, _ := proto.Marshal(msg)
err2 := c.WriteMessage(websocket.BinaryMessage, data)
if err2 != nil {
log.Println("write:", err2)
return
}
case <-interrupt:
log.Println("interrupt")