From 6847abbe5ac81879822faed8592eaeeee82e73cd Mon Sep 17 00:00:00 2001 From: Adam Long Date: Thu, 28 Jul 2016 19:19:27 +0000 Subject: [PATCH] inital commit with server --- server.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 server.py diff --git a/server.py b/server.py new file mode 100644 index 0000000..6173ffc --- /dev/null +++ b/server.py @@ -0,0 +1,34 @@ +import socket +import pygame +import pygame.camera +import sys +import time + +port = 5802 +pygame.init() + +serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +serversocket.bind(("",port)) +serversocket.listen(1) + +pygame.camera.init() +goalCam = pygame.camera.Camera("/dev/video0",(320,240)) +floorCam = pygame.camera.Camera("/dev/video1",(320,240)) +goalCam.start() +floorCam.start() + + +while True: + connection, address = serversocket.accept() + goalImage = goalCam.get_image() # capture image + floorImage = floorCam.get_image() # capture image + merged = pygame.Surface([640,480]) + merged.blit(goalImage,(0,0)) + merged.blit(floorImage,(320,0)) + data = pygame.image.tostring(merged,"RGB") # convert captured image to string, use RGB color scheme + try: + connection.sendall(data) + except socket.error: + print("error") + time.sleep(0.05) + connection.close()