CS 598 Assignment 3: Summary of Chapter 7

Assignment 3: Summary of Chapter 7

CIS 598 – Embedded System Programing

Networked Python

THE WORLD TODAY is more associated than it’s at any point, and nearly everything that you do on PCs has some online part. He Raspberry Pi is no different. For whatever period that you have a Model B or a remote USB dongle, getting your Pi related with the Internet is piddling. Here’s the Midori program you can use to surf the web, and mail customers are accessible. These are useful for expending content—getting data of the internet and utilizing administrations that other individuals have made. The intensity of the Raspberry Pi, be that as it may, lies in making things. With a couple of lines of Python, you can snatch data of the web or utilize your Raspberry Pi to present substance and administrations to the world.

Understanding Hosts, Ports, and Sockets

To speak with another PC, you have to realize where to send information to. It may be that you’re merely sending data to another PC in a similar room, or you may send it mostly round the world. In any case, you have to determine a location. He standard method for finding PCs is by Internet Protocol (IP) address. Here are two sorts of IP address, adaptation 4 and rendition 6. At the season of composing, form 4 (IPv4) is all around utilized, so you’ll peruse just about it. IPv6 addresses work in a similar essential manner, so you shouldn’t have any difficulty utilizing these should they become standard at any point soon.

Locating Computers with IP Addresses

IPv4 addresses contain four numbers separated by dots. To determine your Raspberry Pi’s IP addresses (it has more than one), open a terminal (not a Python session, but an LXTerminal session). And run ifconfig. His should output something like the following:



His shows that there are two network interfaces: eth0 and lo. eth0 is the wired network connection, and lo is the loopback connection that just loops back to the same machine. In the previous example, the Ethernet connection has an IP address of, while the loopback is (this is always the same).

Building a Chat Server

Rather than most of the activities in this book, this program has two segments that need to continue running at the same time: a client and a server. He server sits and trusts that an association will come in, while the customer sets up an association. Here’s the code for the server:

import socket

comms_socket = socket.socket()

comms_socket.bind((‘localhost’, 50000))


connection, address = comms_socket.accept()

while True:


send_data = input(“Reply: “)

connection.send(bytes(send_data, “UTF-8”))

You can see this gets the vast majority of its usefulness from the attachment module. With a server attachment, you first need to tie it to a port on the host. (Any of the ports over 50,000 ought to be free for brief use. You can utilize practically anybody that is not at present use, yet it’s ideal for maintaining a strategic distance from the ones beneath 100 except if you’re certain they’re not to utilize.) tune in() at that point sets it to hang tight for an association. When a connection comes in, it moves onto the following line:

connection, address = comms_socket.accept()