當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Conn.PayloadType方法代碼示例

本文整理匯總了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 := &copySyncer{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)
}
開發者ID:gitinsky,項目名稱:vnc-go-web,代碼行數:28,代碼來源:webSocket.go

示例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()
	}
}
開發者ID:ethicatech,項目名稱:tinybiome,代碼行數:7,代碼來源:websocket.go

示例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)
}
開發者ID:cdshann,項目名稱:minimega,代碼行數:35,代碼來源:tunnel.go

示例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)
	}
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:10,代碼來源:console.go

示例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()
}
開發者ID:platinasystems,項目名稱:weeb,代碼行數:13,代碼來源:main.go

示例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)
	}
}
開發者ID:FabienTregan,項目名稱:theWhitePage,代碼行數:44,代碼來源:server.go


注:本文中的golang.org/x/net/websocket.Conn.PayloadType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。