本文整理匯總了Golang中golang.org/x/net/websocket.Conn.PayloadType方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.PayloadType方法的具體用法?Golang Conn.PayloadType怎麽用?Golang Conn.PayloadType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類golang.org/x/net/websocket.Conn
的用法示例。
在下文中一共展示了Conn.PayloadType方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleWss
func handleWss(wsconn *websocket.Conn) {
p := Responder{nil, wsconn.Request(), time.Now()}
serverIP := wsconn.Request().Header.Get("X-Server-IP")
conn, err := net.Dial("tcp", serverIP)
if err != nil {
p.errorLog(http.StatusInternalServerError, "Error connecting to '%s': %s", serverIP, err.Error())
wsconn.Close()
return
}
defer conn.Close()
defer wsconn.Close()
wsconn.PayloadType = websocket.BinaryFrame
t := ©Syncer{alive: true}
go p.CopyR2W(t, conn, wsconn, serverIP+" ws2vnc")
go p.CopyR2W(t, wsconn, conn, serverIP+" vnc2ws")
p.errorLog(http.StatusOK, "websocket started: '%s'", serverIP)
for t.IsAlive() {
time.Sleep(100 * time.Millisecond)
}
p.errorLog(http.StatusOK, "websocket closed: '%s'", serverIP)
}
示例2: Accept
func (s *Server) Accept(ws *websocket.Conn) {
ws.PayloadType = websocket.BinaryFrame
if _, err := NewConnection(s, ws); err != nil {
ws.SetDeadline(time.Now().Add(2 * time.Millisecond))
ws.Close()
}
}
示例3: vncWsHandler
func vncWsHandler(ws *websocket.Conn) {
// URL should be of the form `/ws/<vm_name>`
path := strings.Trim(ws.Config().Location.Path, "/")
fields := strings.Split(path, "/")
if len(fields) != 2 {
return
}
vmName := fields[1]
vms := GlobalVMs()
vm, err := vms.findKvmVM(vmName)
if err != nil {
log.Errorln(err)
return
}
// Undocumented "feature" of websocket -- need to set to PayloadType in
// order for a direct io.Copy to work.
ws.PayloadType = websocket.BinaryFrame
// connect to the remote host
rhost := fmt.Sprintf("%v:%v", vm.Host, vm.VNCPort)
remote, err := net.Dial("tcp", rhost)
if err != nil {
log.Errorln(err)
return
}
defer remote.Close()
go io.Copy(ws, remote)
io.Copy(remote, ws)
log.Info("ws client disconnected from %v", rhost)
}
示例4: Websocket
func (c Console) Websocket(conn *websocket.Conn) {
conn.PayloadType = websocket.BinaryFrame
r := byteio.StickyReader{Reader: &byteio.LittleEndianReader{conn}}
w := byteio.StickyWriter{Writer: &byteio.LittleEndianWriter{Writer: conn}}
err := c.handle(&r, &w)
if err != nil {
writeError(&w, err)
}
}
示例5: handle_ws
func handle_ws(ws *websocket.Conn) {
// Gob based RPC requires binary web socket frames.
ws.PayloadType = websocket.BinaryFrame
l := &Listener{}
r := weeb.NewRpc(ws, l)
l.rpc = r
// go HelloRpcClient(r)
err := r.Serve()
if err != io.EOF {
log.Printf("%v", err)
}
ws.Close()
}
示例6: echoHandler
func echoHandler(ws *websocket.Conn) {
fmt.Printf("Player joined : ", ws)
defer ws.Close()
x1 := uint16(0)
y1 := uint16(0)
x2 := uint16(1)
y2 := uint16(1)
ws.PayloadType = websocket.BinaryFrame
clientData := make([]byte, 100)
for {
n, err := ws.Read(clientData)
if err != nil {
fmt.Printf("Error on stream ", err.Error())
ws.Close()
return
}
s := string(clientData[:n])
//fmt.Printf("Received: %d bytes: %v (string is %v)\n", n, clientData[:n], s)
switch s {
case "D":
x1++
case "Q":
x1--
case "S":
y1++
case "Z":
y1--
}
data := [4]uint16{x1, y1, x2, y2}
data2 := toBytes(data)
n, err = ws.Write(data2)
}
}