summaryrefslogtreecommitdiff
path: root/server.py
blob: 4e5cd6545465508fd20340146fbb2c2daa5c3ca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import cv2
import os
import socket
import sys

server_address = '/home/flo/uds_socket'
try:
    os.unlink(server_address)
except OSError:
    if os.path.exists(server_address):
        raise

# Create a UDS socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

# Bind the socket to the port
print >>sys.stderr, 'starting up on %s' % server_address
sock.bind(server_address)

# Listen for incoming connections
sock.listen(1)

while True:
    # Wait for a connection
    print >>sys.stderr, 'waiting for a connection'
    connection, client_address = sock.accept()
    try:
        print >>sys.stderr, 'connection from', client_address
        cap = cv2.VideoCapture("/home/flo/outvid2.avi")

        # Receive the data in small chunks and retransmit it
        while True:
            data = connection.recv(16)
            print >>sys.stderr, 'received "%s"' % data
            if data:
                if data=="get\n":
                    status, frame = cap.read()
                    print >>sys.stderr, 'sending image to the client'
                    connection.sendall(frame.tostring())
                    cv2.imshow("img",frame)
                    cv2.waitKey(20)
            else:
                print >>sys.stderr, 'no more data from', client_address
                break
            
    finally:
        # Clean up the connection
        connection.close()

while True:
    status, frame = cap.read()
    cv2.imshow("img",frame)
    cv2.waitKey(20)