Question

I have the following python script that connects to my website and reads a text file. It then forwards the value that it read from the text file to the USB serial port. I need to find out how it relates to networking concepts and what layers and protocols it might be using in the background. For example, I know its using TCP/IP. What other details are related? Thanks..

import time
import urllib
import serial

# usb serial connection to arduino
ser = serial.Serial('COM4', 9600)
myUrl = 'http://somewebsite/hitcounter.txt'

last_counter = urllib.urlopen(myUrl).read()
while (True):
    counter = urllib.urlopen(myUrl).read()
    delta = int(counter) - int(last_counter)
    print "counter: %s, delta: %s" % (counter, delta)
    ser.write(chr(ord(chr(delta))))
    last_counter = counter
Was it helpful?

Solution

The best way to find out what is going on between your PC and the remote website in terms of networking is to go download an application such as Wireshark and have a look at the packet exchanges when you run your script.

Depending on how deep you want to go, the key protocols involved will be TCP as the transport and HTTP as the application-layer protocol.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top