using python . tcp client code from socket import * serverIP = ' XXXXXXXXXX' serverPort = 12000 clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverIP,serverPort)) sentence =...



using python .


tcp client code

from socket import *
serverIP = '127.0.0.1'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverIP,serverPort))
sentence = input('Input lowercase sentence:')
clientSocket.send(sentence.encode())
modifiedSentence = clientSocket.recv(1024)
print ('From Server:', modifiedSentence.decode())
clientSocket.close()


tcp server code

from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind(('',serverPort))
serverSocket.listen(1)
print ('The server is ready to receive')
while True:
connectionSocket, addr = serverSocket.accept()


sentence = connectionSocket.recv(1024).decode()
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence.encode())
connectionSocket.close()





  • In a while loop:


    • Client needs to take a number from the user

    • Client will send this number to the server

    • The server will display a message that he got this number from this specific client (print IP address and port number of client)

    • The server will check if this nummber is odd or even or zero

    • The server will send the output of this check (even/odd/zero) to the client

    • The client will print the output of the check to the user

    • This while loop will break if the user enters 1000000



  • Please note that the port number of the client is assigned dynamically by OS



Screenshot of Server cmd:


C:\Users\Student\Desktop\Python codes>python TCPServer.py
The server is ready to receive
The number is:  22     is received from:  ('127.0.0.1', 12)
The number is:  5     is received from:  ('127.0.0.1', 12)




Screenshot of client 1 cmd:


C:\Users\Student\Desktop\Python codes>python TCPClient.py


Enter the number: 22


The number is even


Enter the number: 5


The number is odd


Enter the number: 1000000



You need to submit 4 files (each 1.25 grade)



  • server code (.py or .txt)

  • client code (.py or .txt)

  • server cmd screenshot

  • client cmd screenshot



Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here