Deploying a networked application
Setup
- Create a new directory called
quote-server/ - Download
quote_client.pyand place it in the new directory.
Concepts
Networked applications are any program that listen for data to arrive over a network socket. Several networked applications are running on your computer right now that are part of your operating system. Web browsers, games, video chat apps are all examples of network applications.
What is the data that arrives over the network? Initially it is treated as raw bytes, but those bytes could represent text that you process as strings, numbers, file data, or other things. The software engineer writes code that processes the bytes into whatever type they represent, and then writes normal program logic to operate on that data. The basics of working with data from a network is quite simple, actually, but what programs can do with that data can be enormously complex.
Some important terms:
- Server: The computer or program that is waiting for connections.
- Client: The computer or program that is initiates connections. Once connected to a server, they can exchange data.
- Socket: the combination of network address and logical port that a program uses to send and receive data, e.g.,
152.20.12.250:25555. 127.0.0.1: this IP address is “home” and is shorthand for your local computer
Creating a local server application
We will write in class a simple server application in Python that:
- listens for network data on a specified socket.
- sends a random question to a client that connects to the socket.
Deploying software to ada
Deployment is the act of making your software available for use. You could deploy your software to your own computer (you do this while testing). For other people to use your software, you need to make your computer accessible via a network and make sure the program is running all the time and ensure that your computer has enough resources to handle thousands of people using it all at once.
Hence, servers. Servers are network accessible and all they do (usually) is serve software programs that users can connect to.
So, how can you get a program to ada? You can use file transfer tools like scp, but we will use git.
Create a new GitHub repository
We will place your quote-server project on GitHub.
- Login to https://github.com on your local computer.
- Create a new repository named
quote-server. Leave everything to the default. - Run
git initin yourquote-server/directory on your computer. - Run the set of commands from the GitHub repo page to “…or push an existing repository from the command line” that look like this:

- Reload your GitHub webpage to ensure the repo is pushed.
Initializing Git and GitHub on ada
We need to authorize your account on ada to clone your remote repositories. Do the following:
- Use a Terminal to
ssh <your_id>@ada.cis.uncw.edu(you must be on a campus network or VPN) - Run
gh auth login. Accept the default options. - The step
Press Enter to open https://github.com/login/device in your browser...becauseadadoesn’t have a GUI.
- On your computer, open a browser to https://github.com/login/device and type in the 8-character code on
ada’s terminal. - In the browser, accept the authorization options:

- You should see in the
adaTerminal a “Logged in as” message. You are done. 
Cloning and running the app on the server
Now you can use git on ada to clone the project and pull any changes.
- On
ada, rungit clone <YOUR_REPO URL>to clone your repo. cdinto the cloned directory- run
python3 quote_server.py
If successful, you should see a startup message saying the server is running. You are good to proceed to the next section.
If you see an error message, it may mean that someone else has chosen the same PORT number as you. No problem.
- If so, run
nano quote_server.pyand change the port number to something unique between 10,000-60,000 that is unique. - Hit
CTRL+XthenYto save and exit. - Run
python3 quote_server.pyagain. - If you still get an error, go to Step 1 or ask the instructor.
- Remember to
git add,commit, andpushany changes! - You can stop the server app by hitting
CTRL+Cor closing the connection to ada.
Testing the server
On your local computer:
- Run
git pullif you pushed changes to your server code! - Run the
quotes_client.pyscript. - Hit
cto connect. - Enter
152.20.12.250:PORTwherePORTis what you set in thequote_server.pyonada - Hit
ra few times. Your quotes are now streaming from your server application onadato the client application on your computer!
Connecting to ada’s quote server registry
I created a web application that lists all the quote servers running on ada. You can see it here if on the UNCW network or VPN: http://152.20.12.250:22222/
You can add your application to the registry. To do so, you need code that talks to the registry when your server app starts.
Do the following with your quote_server.py in your computer.
- Paste the following function into
quote_server.py:def transmit_server_info(): """Connects to a predefined IP and port and transmits the server's ipaddress, port, and server_name.""" try: # Connect to predefined target client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect((TARGET_IP, TARGET_PORT)) # Prepare data to transmit data = f"{PORT},{SERVER_NAME}" # Transmit the information client_socket.send(data.encode()) print(f"Transmitted server info to {TARGET_IP}:{TARGET_PORT} - {data}") client_socket.close() except Exception as e: print(f"Error transmitting server info: {e}") - Invoke
transmit_server_info()before yourwhileloop. - Git add, commit, and push.
- Connect to
ada, pull your changes. - Run your server again with
python3 quote_server.py. Your quote server should appear in the registry within a few seconds.
You can use quote_client.py to connect to answer server in the registry (use their IP+PORT address) so long as you are on the campus network or VPN. Nifty!
Note that your server will shutdown when you logout. You may cancel it manually with CTRL+C.