07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

212 Chapter 7 ■ Message Integrity

Sending Secure Messages Over IP Networks

Sockets are used to send messages across various networks that can be logical,

local, or external. Sockets were introduced back in 1971 with the birth of ARPANET

and then later became the Berkeley sockets, which is an API in the Berkeley

Software Distribution OS that was released in 1983. Network programming

started to boom in the 1990s as the use of the internet increased; the use of

client-server applications of many types became widespread. The socket API

in Python provides an interface to the Berkley sockets.

There are two types of sockets that you can experiment with. The first is a

Transmission Control Protocol (TCP). TCP is used to produce reliability and has

an in-order data delivery system. The second type of socket is the User Datagram

Protocol (UDP). These sockets lack reliability and their data can be out

of order; in fact, there is no guarantee that your data will reach the destination.

Depending on the type of data you are sending, one type of socket will have

advantages over the other. In the next two code samples provided, you will use

Python to create a server listening for UDP communications and create a client

server that will communicate with it.

Create a Server Socket

The following Python code will allow you to create a server that is listening

on port 13000. Once this code executes, it will launch a command window that

states Waiting to receive message. . . . See Figure 7.3.

Figure 7.3: Output of Server.py

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!