A game server project with python and js Python as front-end client and node.js as backend server. Using socket.io to communicate between the two.
Requirements:
- python3 (3.9.0) and pip (20.1.1)
- npm (6.14.8)
Note:
- pip is installed with python automatically.
- Instructions may vary for Windows and MacOS.
- Specific versions may not be required.
- Fork this repo (use github web portal)
- Clone your repo to your local computer. (Let's say /home/you/git/game-nation)
git clone https://github.com/code-mentoring/game-nation.git
- Navigate to your new project folder (/home/you/git/game-nation)
You should see at least some "test-*" files and README.md
cd /home/you/git/game-nation
Note: Windows users might need to append py -m
to some of the below commands.
-
Get virtualenv (this will help isolate installations to be project specific).
pip install virtualenv
-
Create a virtual environment for this project (use path to your python)
virtualenv -p /usr/bin/python3 .
You should see new directories
bin
andlib
now in your project dir. Windows users should seeLib
andScripts
instead. -
Activate your virtual env (once activated installations will be local to this folder)
source bin/activate
Windows(PowerShell):
Scripts\activate.ps1
Windows(cmd):
call Scripts\activate
Note:
source
command reads and executes commands from given FILENAME; Windows equivalent iscall
. -
Install socketio for python (server, client and dependencies)
pip install python-socketio pip install python-socketio[client] pip install eventlet
-
Test your python server:
python3 test-server.py
You should see something like:
SERVER: (96370) wsgi starting up on http://0.0.0.0:5000
-
Test your python client (Leave the server running, then from another terminal, same project dir):
source bin/activate python3 test-client.py
You should see something like:
CLIENT: connection established SERVER: (96370) accepted ('127.0.0.1', 60006)
-
If all looks okay you can kill the client and server ctrl-C (on CLI usually)
- Install socket io and express
npm install socket.io npm install express
- Test server
From your browser, enter "localhost:5000" in address bar.
node test-server.js
BROWSER: "hello world" SERVER: "a user connected"
- Test python client with js server (from same location in another terminal,
Again from your project directory with activated virtual environment)
python3 test-client.py
CLIENT: "connection established" SERVER: "a user connected"
- Cool, looks like you have (a very simple) python client application talking to a javascript server via socketio.
- Python should have tkinter installed by default. This command will output error if it is not correctly installed.
python3 test-gui.py
- See
How to keep a fork repo up to date?
in our FAQ page.