本文整理匯總了Golang中github.com/eclipse/che-lib/websocket.Conn.ReadMessage方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.ReadMessage方法的具體用法?Golang Conn.ReadMessage怎麽用?Golang Conn.ReadMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/eclipse/che-lib/websocket.Conn
的用法示例。
在下文中一共展示了Conn.ReadMessage方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sendConnectionInputToPty
// read from the web socket, copying to the pty master
// messages are expected to be text and base64 encoded
func sendConnectionInputToPty(conn *websocket.Conn, reader io.ReadCloser, f *os.File, finalizer *ReadWriteRoutingFinalizer) {
defer closeReader(reader, f, finalizer)
for {
mt, payload, err := conn.ReadMessage()
if err != nil {
if !isNormalWsError(err) {
log.Printf("conn.ReadMessage failed: %s\n", err)
}
return
}
switch mt {
case websocket.BinaryMessage:
log.Printf("Ignoring binary message: %q\n", payload)
case websocket.TextMessage:
var msg WebSocketMessage
if err := json.Unmarshal(payload, &msg); err != nil {
log.Printf("Invalid message %s\n", err)
continue
}
if errMsg := handleMessage(msg, f); errMsg != nil {
log.Printf(errMsg.Error())
return
}
default:
log.Printf("Invalid websocket message type %d\n", mt)
return
}
}
}
示例2: readMessages
// Reads the message from the websocket connection until error is received,
// returns the channel which should be used for reading such messages.
func readMessages(conn *websocket.Conn) chan *WsMessage {
messagesChan := make(chan *WsMessage)
go func() {
for {
_, bytes, err := conn.ReadMessage()
messagesChan <- &WsMessage{err: err, bytes: bytes}
if err != nil {
close(messagesChan)
break
}
}
}()
return messagesChan
}