-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (43 loc) · 998 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"math/rand"
"net/http"
"sync"
"github.com/gorilla/websocket"
"github.com/rs/cors"
)
var (
clientRooms = make(map[string]*Room)
clientRoomsLock sync.RWMutex
randomRooms = make([]*Room, 0, 10)
randomRoomsLock sync.Mutex
)
const NUM = 4
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize:1024,
CheckOrigin: func(r *http.Request) bool {
return true // Allow all origins
},
}
func handleConnections(w http.ResponseWriter, r *http.Request) {
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
fmt.Println(err)
return
}
wsClient := &WSClient{Conn: conn, RoomName: "", UniqueNumber: rand.Int(), Number: -1}
wsClient.HandleClient()
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", handleConnections)
handler := cors.Default().Handler(mux)
server := &http.Server{
Addr: ":5000",
Handler: handler,
}
fmt.Println("Server is running on port 5000!")
server.ListenAndServe()
}