$user->password = password_hash($data['password'], PASSWORD_DEFAULT);
package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/websocket"
)
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool { return true },
}
func reader(conn *websocket.Conn) {
for {
// read in a message
messageType, p, err := conn.ReadMessage()
if err != nil {
log.Println(err)
return
}
// print out that message for clarity
fmt.Println(string(p))
if err := conn.WriteMessage(messageType, p); err != nil {
log.Println(err)
return
}
}
}
// define our WebSocket endpoint
func serveWs(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Host)
// upgrade this connection to a WebSocket
// connection
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Println(err)
}
reader(ws)
}
func setupRoutes() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Simple Server")
})
// mape our `/ws` endpoint to the `serveWs` function
http.HandleFunc("/ws", serveWs)
}
func main() {
fmt.Println("test 0.01")
setupRoutes()
http.ListenAndServe(":8080", nil)
}
socket.onclose = event => {
console.log("Socket Closed Connection: ", event);
socket.send("Client Closed!")
};
socket.onclose = event => {
console.log("Socket Closed Connection: ", event);
};
2019/11/26 12:13:08 Connected:
2019/11/26 12:13:08 Disonnected:
(index):23 Attempting Connection...
(index):22 WebSocket connection to 'ws://*/ws' failed: Error during WebSocket handshake: Unexpected response code: 200
(anonymous) @ (index):22
(index):36 Socket Error: Event {isTrusted: true, type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …}
(index):31 Socket Closed Connection: CloseEvent {isTrusted: true, wasClean: false, code: 1006, reason: "", type: "close", …}
(index):32 WebSocket is already in CLOSING or CLOSED state.
socket.onclose @ (index):32