28 lines
635 B
Go
28 lines
635 B
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gorilla/websocket"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestWEBs(t *testing.T) {
|
|
var upgrader = websocket.Upgrader{ReadBufferSize: 1024, WriteBufferSize: 1024, HandshakeTimeout: 5 * time.Second}
|
|
http.HandleFunc("/websocket", func(w http.ResponseWriter, r *http.Request) {
|
|
conn, _ := upgrader.Upgrade(w, r, nil)
|
|
for {
|
|
msgType, msg, err := conn.ReadMessage()
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Printf("%s receive: %s\n", conn.RemoteAddr(), string(msg))
|
|
if err = conn.WriteMessage(msgType, msg); err != nil {
|
|
return
|
|
}
|
|
}
|
|
})
|
|
http.ListenAndServe(":12345", nil)
|
|
}
|