0

I have two python scripts named server.py (server script) and client.py(client script). The client sends the server a list and and a string. Below is the source code:

client.py

import socket,pickle 

HOST = 'localhost'
PORT = 50007
# Create a socket connection.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))


variable =[1,3,4,5,67]
# Pickle the object and send it to the server
data_string = pickle.dumps(variable)
s.send(data_string)
s.send(str.encode("Hello world"))

s.close()
print ('Data Sent to Server')

server.py

import socket, pickle


HOST = 'localhost'
PORT = 50007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print ('Connected by', addr)
data=conn.recv(4096)
data_variable = pickle.loads(data)
sentence=conn.recv(4096).decode()
conn.close()
print (data_variable)
print(sentence)

print ('Data received from client')





Output on server side after executing client.py and server.py

Connected by ('127.0.0.1', 54182)
[1, 3, 4, 5, 67]

Expected output on server side after executing client.py and server.py

Connected by ('127.0.0.1', 54182)
[1, 3, 4, 5, 67]
Hello world

0 Answers0