feat(项目): 项目初始化
This commit is contained in:
30
common/common.go
Normal file
30
common/common.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func WsToTcpHandler(conn net.Conn, wsConn *websocket.Conn) {
|
||||
for {
|
||||
_, p, err := wsConn.ReadMessage()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
conn.Write(p)
|
||||
}
|
||||
}
|
||||
|
||||
func TcpToWsHandler(conn net.Conn, wsConn *websocket.Conn) {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
n, err := conn.Read(buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
wsConn.WriteMessage(websocket.BinaryMessage, buf[:n])
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user