0% found this document useful (0 votes)
71 views

Socket Programming: Lab Exercise

The document discusses socket programming in Python, describing how a client-server model works with a server waiting for client requests and clients requesting resources from the server. It provides an example of setting up a Python socket server and client on either the same machine or different machines, with the client initiating the connection, sending a message, and closing the connection which then causes the server to terminate. The document also gives examples of the code needed for both the server and client Python programs.

Uploaded by

Santhosh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Socket Programming: Lab Exercise

The document discusses socket programming in Python, describing how a client-server model works with a server waiting for client requests and clients requesting resources from the server. It provides an example of setting up a Python socket server and client on either the same machine or different machines, with the client initiating the connection, sending a message, and closing the connection which then causes the server to terminate. The document also gives examples of the code needed for both the server and client Python programs.

Uploaded by

Santhosh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Socket Programming

Lab Exercise
• Host
• Sender and receiver
• Client and server
• Socket – port+IP
Client, Server and Socket
• A server is a software that waits for client requests
and serves or processes them accordingly.
• a client is requester of this service. A client program
request for some resources to the server
• Socket is the endpoint of a bidirectional
communications channel between server and client.
• Sockets may communicate within a process,
between processes on the same machine, or
between processes on different machines. 
Python Socket Example
• Two programs – client.py server.py
• Two machines or one machine – two command prompt
• Complete server.py
• Go to command prompt
• Execute server.py
• Python socket server program executes at first and wait for any request
• Write client. py
• Go to new command prompt
• Execute client.py
• TCP socket program
• Port address and IP, TCP socket – connection estalblishment data transfer connection close

• Python socket client program will initiate the conversation at first.


• Then server program will response accordingly to client requests.
• Client program will terminate if user enters “bye” message. Server program will also terminate when
client program terminates, this is optional and we can keep server program running indefinitely or
terminate with some specific command in client request.
Server.py Example
• host = socket.gethostname() – IP address
• port = 5000
• server_socket = socket.socket()
• server_socket.bind((host, port))
• server_socket.listen(2)
• conn, address = server_socket.accept()
• conn.recv(1024).decode()
• conn.send(data.encode())
Client.py Example
• host = socket.gethostname()
• port = 5000
• client_socket = socket.socket()
• client_socket.connect((host, port))
• client_socket.send(message.encode())
• data = client_socket.recv(1024).decode()
https://www.journaldev.com/15906/python-
socket-programming-server-client
• 64 – no. of host bits – 6= 32-6 – 26
• 128 – 7 – 32- 7 - 25
• 223.1.1.0/24
• 223.1.1.0 to 223.1.1 63
• 223.1.1.64 to 223.1.1.191
• 223.1.1.192 to 199
• 199 to 203
DNS – Reverse DNS and ARP- RARP

An ARP cache is a collection of Address Resolution Protocol entries (mostly dynamic) that
are created when an IP address is resolved to a MAC address (so the computer can
effectively communicate with the IP address).
• “192.168.10.10”, “FF.CC.DD.11”
• “192.168.10.1”, “CC.FF.11.22”
• “192,168.0.1”, “DD.11.2.2”
• 192.168.1.120”,”AA.1.1.1”
• Str[4][2]
• If(data==str[0][0])
• Data=str[0][1]
• Data.encode()

You might also like