0% found this document useful (0 votes)
23 views2 pages

Figure 1: Screenshot For Server

Code Description for Socketing in python

Uploaded by

Jojo Henkens
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Figure 1: Screenshot For Server

Code Description for Socketing in python

Uploaded by

Jojo Henkens
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Code Description:

In socket.py code, a socket.socket() constructs a socket object with the context manager class
supported. socket.AF_INET, socket.SOCK_STREAM makes it a TCP connection.
The values passed to bind() are determined by the socket's address family. We're using socket.AF_INET.
As a result, it anticipates a two-tuple: (Host and port)
The host parameter may be either a hostname, an IP address, or an empty string. If an IP address is
used, the host parameter should be an IPv4 address string. Only processes on the host would be able to
bind to the server since the IP address 127.0.0.1 is the normal IPv4 address for the loopback protocol.
The server will allow connections on all available IPv4 interfaces if you pass an empty string.
The port number should range from 1-65535. (0 is reserved). It's the TCP port number for accepting
client connections. If the port is less than 1024, certain devices can need superuser privileges.

accept() allows a server to accept connections by calling listen().

accept() takes a break and waits for a connection to arrive. When a client establishes a link, it returns a
new socket object and a tuple containing the information about the connection.

An endless while loop is used to loop over blocking calls to conn.recv() after receiving the network
socket object conn from accept() (). This reads data the client sends i.e. s1 and s2 and concatenates then
as s2 followed by s1 and uses conn.sendall() to echo it back. And once the connection is closed it waits
for another.

Function sendable_data() encodes the parameter in utf-8 format.

Figure 1: Screenshot for Server

In client.py , a socket objects is created which connects to server asks user for a string, splits it into two
halves and sends both of the halves s1 and s2 to the server using s.sendall().Recieves data from server
using s.recv() i.e r from server, compares it with concatenation of s2 and s1 if it returns true “Data
Successfully Trasmitted” is printed else, “Data Not Successfully Trasmitted” is printed.
Figure 2: Screenshot for Client

You might also like