本文整理匯總了Golang中github.com/eclipse/che-lib/websocket.Conn.WriteMessage方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.WriteMessage方法的具體用法?Golang Conn.WriteMessage怎麽用?Golang Conn.WriteMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/eclipse/che-lib/websocket.Conn
的用法示例。
在下文中一共展示了Conn.WriteMessage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sendPtyOutputToConnection
// copy everything from the pty master to the websocket
// using base64 encoding for now due to limitations in term.js
func sendPtyOutputToConnection(conn *websocket.Conn, reader io.ReadCloser, finalizer *ReadWriteRoutingFinalizer) {
defer closeConn(conn, finalizer)
buf := make([]byte, 8192)
var buffer bytes.Buffer
for {
n, err := reader.Read(buf)
if err != nil {
if !isNormalPtyError(err) {
log.Printf("Failed to read from pty: %s", err)
}
return
}
i, err := normalizeBuffer(&buffer, buf, n)
if err != nil {
log.Printf("Cound't normalize byte buffer to UTF-8 sequence, due to an error: %s", err.Error())
return
}
if err = conn.WriteMessage(websocket.TextMessage, buffer.Bytes()); err != nil {
log.Printf("Failed to send websocket message: %s, due to occurred error %s", string(buffer.Bytes()), err.Error())
return
}
buffer.Reset()
if i < n {
buffer.Write(buf[i:n])
}
}
}