Deploying a networked application

Writing a simple server application that listens for network connections and deploying it to ada

Setup

  • Create a new directory called quote-server/
  • Download quote_client.py and 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:

  1. listens for network data on a specified socket.
  2. 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.

  1. Login to https://github.com on your local computer.
  2. Create a new repository named quote-server. Leave everything to the default.
  3. Run git init in your quote-server/ directory on your computer.
  4. Run the set of commands from the GitHub repo page to “…or push an existing repository from the command line” that look like this:
    instructions to push an existing repo to github
  5. 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:

  1. Use a Terminal to ssh <your_id>@ada.cis.uncw.edu (you must be on a campus network or VPN)
  2. Run gh auth login. Accept the default options.
  3. The step Press Enter to open https://github.com/login/device in your browser... because ada doesn’t have a GUI.
    failure message when trying ot open a browser window on ada
  4. On your computer, open a browser to https://github.com/login/device and type in the 8-character code on ada’s terminal.
  5. In the browser, accept the authorization options:
    GitHub authorization screen
  6. You should see in the ada Terminal a “Logged in as ” message. You are done.
    ada terminal showing a successful completion

Cloning and running the app on the server

Now you can use git on ada to clone the project and pull any changes.

  1. On ada, run git clone <YOUR_REPO URL> to clone your repo.
  2. cd into the cloned directory
  3. 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.

  1. If so, run nano quote_server.py and change the port number to something unique between 10,000-60,000 that is unique.
  2. Hit CTRL+X then Y to save and exit.
  3. Run python3 quote_server.py again.
  4. If you still get an error, go to Step 1 or ask the instructor.
  5. Remember to git add, commit, and push any changes!
  6. You can stop the server app by hitting CTRL+C or closing the connection to ada.

Testing the server

On your local computer:

  • Run git pull if you pushed changes to your server code!
  • Run the quotes_client.py script.
  • Hit c to connect.
  • Enter 152.20.12.250:PORT where PORT is what you set in the quote_server.py on ada
  • Hit r a few times. Your quotes are now streaming from your server application on ada to 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.

  1. 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}")
    
  2. Invoke transmit_server_info() before your while loop.
  3. Git add, commit, and push.
  4. Connect to ada, pull your changes.
  5. 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.

Last modified November 21, 2025.