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:
parent
46ee8a456f
commit
36a23911a8
|
@ -4,29 +4,39 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "flag"
|
||||||
"flag"
|
import "log"
|
||||||
"log"
|
import "net/url"
|
||||||
"net/url"
|
import "os"
|
||||||
"os"
|
import "os/signal"
|
||||||
"os/signal"
|
import "time"
|
||||||
"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")
|
var addr = flag.String("addr", "v000185.testing.com.customers.wprod.wit.com:9000", "http service address")
|
||||||
|
|
||||||
func readConn(done chan struct{}, conn *websocket.Conn) {
|
func readConn(done chan struct{}, conn *websocket.Conn) {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
for {
|
for {
|
||||||
_, message, err := conn.ReadMessage()
|
mytype, message, err := conn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("read:", err)
|
log.Println("read:", err)
|
||||||
return
|
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)
|
log.Println("write:", err)
|
||||||
return
|
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:
|
case <-interrupt:
|
||||||
log.Println("interrupt")
|
log.Println("interrupt")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue