I have codes for both client and server.
It runs smoothly and it looks like that the picture is sent to the client
like expected, however, I am not sure how to display it.
I used the command 'display' but is not showing anything.
How do I fix it?
P.S. The picture file I am using in the server can be changed by any other
png file, you can test with a random one chosen anywhere.
It runs smoothly and it looks like that the picture is sent to the client
like expected, however, I am not sure how to display it.
I used the command 'display' but is not showing anything.
How do I fix it?
P.S. The picture file I am using in the server can be changed by any other
png file, you can test with a random one chosen anywhere.
#SERVER CODE
import socket
port = 60000
s = socket.socket()
host = socket.gethostname()
s.bind((host, port))
s.listen(5)
print ('Server listening....')
while True:
conn, addr = s.accept() # Establish connection with client.
print ('Got connection from', addr)
data = conn.recv(1024)
print('Server received', repr(data))
filename = 'Lee extended.png'
picfile = open(filename,'rb')
l = picfile.read(1024)
while (l):
conn.send(l)
print('Sent ',repr(l))
l = picfile.read(1024)
picfile.close()
print('Done sending')
conn.send('Thank you for connecting'.encode())
conn.close()#CLIENT CODE
import socket
from IPython.display import display, Image
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 60000 # Reserve a port for your service.
s.connect((host, port))
s.send('Hello server!'.encode())
with open('received_file.png', 'rb') as picfile:
print ('file is open')
while True:
print('receiving data...')
data = s.recv(1024)
print('data=%s', data)
display(Image(picfile))
if not data:
break
#picfile.read(data)
picfile.close()
print('Successfully get the file')
s.close()
print('connection closed')
