diff --git a/cmd/main.go b/cmd/main.go index bf01e97f..17e6b94d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -34,7 +34,7 @@ func createOverlordConnection() (*websocket.Conn, error) { func initilizeOverlord() { overlord := overlord.NewServer() - log.Println("http://localhost:9000") + log.Println("http://localhost:8000") http.HandleFunc("/", overlord.GetWeb) http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static")))) @@ -42,12 +42,11 @@ func initilizeOverlord() { // browser facing port go func() { http.HandleFunc("/ws", overlord.WS) - http.ListenAndServe(":8000", nil) }() // worker facing port http.HandleFunc("/wso", overlord.WSO) - http.ListenAndServe(":9000", nil) + http.ListenAndServe(":8000", nil) log.Println("http://localhost:" + *config.Port) } diff --git a/cws/cws.go b/cws/cws.go index 96b6241c..856bd3d5 100644 --- a/cws/cws.go +++ b/cws/cws.go @@ -180,5 +180,8 @@ func (c *Client) Listen() { } func (c *Client) Close() { + if c == nil || c.conn == nil { + return + } c.conn.Close() } diff --git a/run_local.sh b/run_local.sh index d6de79e7..d2f08e37 100755 --- a/run_local.sh +++ b/run_local.sh @@ -1,5 +1,7 @@ #!/bin/bash -docker build . -t cloud-game-local -docker stop cloud-game-local -docker rm cloud-game-local -docker run --privileged -d --name cloud-game-local -p 8000:8000 cloud-game-local cmd -debug +# Run coordinator first +go run cmd/main.go -overlordhost overlord & +# Wait till overlord finish initialized +# Run a worker connecting to overlord +sleep 3s +go run cmd/main.go -overlordhost ws://localhost:8000/wso diff --git a/run_local_docker.sh b/run_local_docker.sh new file mode 100755 index 00000000..84c59c82 --- /dev/null +++ b/run_local_docker.sh @@ -0,0 +1,8 @@ +#!/bin/bash +docker build . -t cloud-game-local +docker stop cloud-game-local +docker rm cloud-game-local-overlord -f +docker rm cloud-game-local-worker -f +docker run --privileged -d --name cloud-game-local-overlord -p 8000:8000 cloud-game-local cmd -overlordhost overlord +sleep 1s +docker run --privileged -d --name cloud-game-local-worker cloud-game-local cmd -overlordhost ws://localhost:8000/wso