Skip to content

code-mentoring/game-nation

Repository files navigation

game-nation

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.

Dev Environment setup

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.

Get the source

  1. Fork this repo (use github web portal)
  2. 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
    
  3. Navigate to your new project folder (/home/you/git/game-nation)
    cd /home/you/git/game-nation
    
    You should see at least some "test-*" files and README.md

Install Virtualenv and Socketio

Note: Windows users might need to append py -m to some of the below commands.

  1. Get virtualenv (this will help isolate installations to be project specific).

    pip install virtualenv
    
  2. Create a virtual environment for this project (use path to your python)

    virtualenv -p /usr/bin/python3 .
    

    You should see new directories bin and lib now in your project dir. Windows users should see Lib and Scripts instead.

  3. 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 is call.

  4. Install socketio for python (server, client and dependencies)

    pip install python-socketio
    pip install python-socketio[client]
    pip install eventlet
    
  5. 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
    
  6. 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)
    
  7. If all looks okay you can kill the client and server ctrl-C (on CLI usually)

Install npm express and socket.io (still in project dir)

  1. Install socket io and express
    npm install socket.io
    npm install express
    
  2. Test server
    node test-server.js
    
    From your browser, enter "localhost:5000" in address bar.
    BROWSER: "hello world"
    SERVER: "a user connected"
    
  3. 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"
    
  4. Cool, looks like you have (a very simple) python client application talking to a javascript server via socketio.

Test tkinter is installed correctly

  1. Python should have tkinter installed by default. This command will output error if it is not correctly installed.
    python3 test-gui.py
    

Keep your fork repo up to date

  • See How to keep a fork repo up to date? in our FAQ page.

About

A game server project with python and js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published