![]() |
client-server pictures - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: client-server pictures (/thread-21868.html) |
client-server pictures - mcgrim - Oct-18-2019 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. #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') RE: client-server pictures - mcgrim - Oct-20-2019 Let me please know if there is any additional info you would like me to add in order to get at least an answer. RE: client-server pictures - mcgrim - Oct-21-2019 ----- RE: client-server pictures - mcgrim - Oct-21-2019 nobody knows ? RE: client-server pictures - micseydel - Oct-25-2019 https://bit.ly/2Wekgkd |