Sending images using sockets in python
My intention for this program is that it sends an image from the Raspberry pi camera to a client which then can analyse the image with a neural network (uses python). My problem is that I currently get the following error and am unable to get any data on the client side: line 16, in <module> d = connection.read() io.UnsupportedOperation: read Idea's for a more robust solution are welcome to as I am a novice with network programming. client import socket import io from PIL import Image client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect(('XXX.XXX.XXX.XXX', XXXX)) # Make a file-like object out of the connection connection = client_socket.makefile('wb') while 1: message =  while True: d = connection.read(1024*1024) if not d: break else: message.append(d) data = ''.join(message) im = io.StringIO(data) #print(data) image = Image.open(io.BytesIO(im)) #image.show() connection.close() client_socket.close() server import io import time import socket import picamera from PIL import Image server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) PORT = XXXX for x in range(0, 5): try: server_socket.bind(('0.0.0.0', PORT + x)) print('Using PORT: ', PORT + x) except socket.error as exc: pass else: break server_socket.listen(0) # Accept a single connection and make a file-like object out of it connection = server_socket.accept().makefile('wb') # Create the in-memory stream stream = io.BytesIO() with picamera.PiCamera() as camera: #camera.start_preview() camera.resolution = (600, 600) time.sleep(1) camera.capture(stream, format='jpeg') connection.write(stream.read()) connection.flush() stream.seek(0) stream.truncate() server_socket.close()
You open the socket with mode 'wb' but then you want to read from it? I think you need client_socket.make file('rb')
Tkinter grid problems
ValueError: Invalid header value 'H2O Python client/2.7.9 (default, Apr 2 2015, 15:33:21) \n[GCC 4.9.2]'
Twitter search with urllib2 failing
is mayavi ready for enaml or stick with traits for gui design?
Check for values return from EnumValue
python socket programming with Tkinter GUI
TypeError: unsupported operand type(s) for 'Instance' and 'Int'
Generate a dictionnary in a list
Why this python script does not work?
Selenium Webdriver Python page object MainPageLocators class why does it use an asterisk infront of the class name
Is it possible to stop Tkinter window freezing during update?
How can I require an api-token field on requests?
pip error while installing mayavi
import matplotlib._png as _png Import: Error: DLL load failed: The specified module could not be found
Retrieving data from OPC-Server
Python: ascii codec can't encode en-dash