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.

214 Chapter 7 ■ Message Integrity

Figure 7.4: Messages entered here will be sent unencrypted to the server.

Create a Threaded Server with TCP

You can expand on your socket knowledge by examining the next code listing.

The following script will create a server that you can send messages to via TCP.

This example, just like the previous communications, sends data unencrypted

from one application to another:

import socket

import sys

from _thread import *

host = 'localhost'

port = 5555

print (host, port)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:

s.bind((host, port))

except socket.error as e:

print(str(e))

s.listen(5)

def threaded_client(conn):

conn.send(str.encode('Welcome, type your info\n'))

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

Saved successfully!

Ooh no, something went wrong!