Skip to content

PiusNyakoojo/golang_multiplayer_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang_multiplayer_template

This is a template for using the Go programming language and websockets to build realtime, browser-based, multiplayer experiences. The 3D graphics is associated with the three.js library.

Configuration Files

The Godeps folder contains dependency management files for deploying to Heroku.

Procfile is a configuration file for deploying to Herkou.

If you deploy to Google App Engine you'll have to add an app.yaml file and delete the aforementioned config files.

The .project file enables you to open this project in Eclipse ( make sure you have the Goclipse plugin ). Otherwise, it's yet another config file. You can delete it if you'd like.

Run Locally - Terminal

  1. Have Go installed: https://golang.org

  2. Set the GOPATH environment variable to the root directory of this project. Of course if you have other GOPATH routes just add

;C:\Users\YourName\Desktop\golang_multiplayer_template

to the end of the value. Of course this is if you clone this repository to your Desktop :)

  1. Open git bash terminal and change directory to be root of the project
cd Desktop/golang_multiplayer_template
  1. In the same terminal enter the command:
go run src/server/server.go

The application should be running and listening to port 8081

If you are deploying the application, change the websocket address/port in the html/client.html file.

Deploy - Heroku

  1. Have a heroku account (don't worry, it's free for your first few applications): https://heroku.com/

  2. If this is your firt time using Heroku, get the toolbelt: https://toolbelt.heroku.com/ and after installation, open the git bash terminal and enter the following commands:

heroku login

Enter your information and continue to the next step.

  1. Enter the following commands while in the root directory of the project:
git init
git add -A .
git commit -m "initial commit"
heroku create -b https://github.com/kr/heroku-buildpack-go.git
  1. Change the pubAddr variable in html/client.html and comment out and replace the addr variable.
// var addr = "localhost:8081"
var pubAddr = document.domain;

var conn = new Websocket("wss://" +  pubAddr + "/ws");
  1. In the html/client.html file there is a section of code that's commented out.. Go ahead and uncomment that.

  2. Finally deploy!! In the git bash terminal enter the following commands:

git add -A .
git commit -m "changed websocket address"
git push heroku master

To open, just go to the URL provided -or- enter the command:

heroku open

Enjoy!

About

Template for building realtime, multiplayer games with Go and websockets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages