NetworkConnection Module
The NetworkConnection module allows us to talk about networking without worrying about the low level networking protocols that underlie the module. However, this level of abstraction can also cause some undesired behaviors. Let's explore how this module works, and see if there are undesired side-effects.
For each of the following, specify how each of the programs would behave. Specifically, write what each end would print, and label them with the order they are printed.
-
Server: (address is lab-mcsp-00)
import network_connection PORT = 8000 print("Starting server on port", PORT) connection = network_connection.accept(PORT) print("Someone connected!")
Client:
import network_connection PORT = 8000 print("Connecting to server on port", PORT) connection = network_connection.connect("lab-mcsp-00", PORT) print("Connected!")
-
Server: (address is lab-mcsp-00)
import network_connection PORT = 8000 print("Starting server on port", PORT) connection = network_connection.accept(PORT) print("Someone connected!") print("Starting server on port", PORT + 1) connection_2 = network_connection.accept(PORT + 1) print("Someone else connected!")
Client:
import network_connection PORT = 8001 print("Connecting to server on port", PORT) connection = network_connection.connect("lab-mcsp-00", PORT) print("Connected!")
-
Server: (address is lab-mcsp-00)
import network_connection PORT = 8000 print("Starting server on port", PORT) connection = network_connection.accept(PORT) print("Someone connected!") print("Starting server on port", PORT + 1) connection_2 = network_connection.accept(PORT + 1) print("Someone else connected!")
Client:
import network_connection PORT = 8000 print("Connecting to server on port", PORT) connection = network_connection.connect("lab-mcsp-00", PORT) print("Connected!")
-
Server: (address is lab-mcsp-00)
import network_connection PORT = 8000 print("Starting server on port", PORT) connection = network_connection.accept(PORT) print("Someone connected!") connection.send("Hello Client!") print("Sent Message") print(connection.receive())
Client:
import network_connection PORT = 8000 print("Connecting to server on port", PORT) connection = network_connection.connect("lab-mcsp-00", PORT) print("Connected!") connection.send("Hello Server!") print("Sent Message") print(connection.receive())
-
Server: (address is lab-mcsp-00)
import network_connection PORT = 8000 print("Starting server on port", PORT) connection = network_connection.accept(PORT) print("Someone connected!") print(connection.receive()) connection.send("Hello Client!") print("Sent Message")
Client:
import network_connection PORT = 8000 print("Connecting to server on port", PORT) connection = network_connection.connect("lab-mcsp-00", PORT) print("Connected!") connection.send("Hello Server!") print("Sent Message") print(connection.receive())
-
Server: (address is lab-mcsp-00)
import network_connection PORT = 8000 print("Starting server on port", PORT) connection = network_connection.accept(PORT) print("Someone connected!") print(connection.receive()) connection.send("Hello Client!") print("Sent Message")
Client:
import network_connection PORT = 8000 print("Connecting to server on port", PORT) connection = network_connection.connect("lab-mcsp-00", PORT) print("Connected!") print(connection.receive()) connection.send("Hello Server!") print("Sent Message")