Because Why Walk When You Can Run?

Now that you know how to write sockets code, you're probably wondering how to run it. You should run it on your terminal, so check out Rohan's tutorial if you are unfamiliar with it.

1. Navigate to the directory containing your files using

$ cd <path>

You don't type the $ (I'm not sure why they even include it. It is just convention I guess. Useless fact: This confused me for like 15 mins when I saw it first) Also, directory is just a fancy CS word for folder.

In my case, I would type

$ cd Documents/sockets_demo/

because sockets_demo is the folder that contains my server and client files and it is in my Documents folder.

2. Run the server

If you're playing your game with people on other computers, choose one person to run the server. Everyone else doesn't need to. If you're just playing on your computer, you will be hosting (obviously).

$ python3 dots_server.py

3. The, run the clients

If you're playing on different computers, everyone can just type in

$ python3 dots_client.py

because they already navigated to the right directory in step 1. (Obviously they would also need dots_client.py on their computers too)

If you are running it all on your own computer, just open a new terminal window (cmd+n on Mac) and do steps 1 and 3 again. Now you have a new friend! If only it was that easy in real life ... :'(

4. Closing the windows

Once you're done playing the game, You can close the windows by going into their respective terminal windows and doing a keyboard interrupt (ctrl+c on Mac). You'll also want to do this for the server. Press it a couple of times for good measure.

Most of the time it takes a bit to close the PORT, so just wait a bit to run the server again.

results matching ""

    No results matching ""