diff options
author | Florian Jung <flo@windfisch.org> | 2014-12-20 21:28:38 +0100 |
---|---|---|
committer | Florian Jung <flo@windfisch.org> | 2014-12-20 21:28:38 +0100 |
commit | ce289fe207c844d8cf8dcfc96881ad064b19eef0 (patch) | |
tree | 5012e20d0f7fee4473e3e6bf74ef3707d2a727c9 | |
parent | 6982b27c2fd9009dc56de87c513b36b363768795 (diff) |
OARRRRR
-rw-r--r-- | client.c | 14 | ||||
-rw-r--r-- | server.py | 15 |
2 files changed, 27 insertions, 2 deletions
@@ -8,6 +8,9 @@ #define SOCKETPATH "/home/flo/uds_socket" void die(const char* msg){perror(msg); exit(1);} +void suicide(const char* msg){ fprintf(stderr, "%s\n", msg); exit(1); } + +unsigned char buffer[67108864]; // must be unsigned. because reasons -_- int main() { @@ -26,6 +29,17 @@ int main() write(sockfd,"get\n",4); + printf("%i\n",read(sockfd, buffer, 4)); + printf("%x%x%x%x\n",buffer[0],buffer[1],buffer[2],buffer[3]); + int framelen = ((buffer[0]*256+buffer[1])*256+buffer[2])*256+buffer[3]; + printf("framelen is %i\n", framelen); + if (framelen > sizeof(buffer)) suicide("buffer too small"); + read(sockfd, buffer, framelen); + + printf("done reading\n"); + + read(sockfd, buffer, 123); + close(sockfd); return 0; } @@ -3,6 +3,12 @@ import os import socket import sys +def encode_int(i): + i = int(i) + return chr( (i/(2**24))%256) + chr( (i/(2**16))%256 ) +\ + chr( (i/(2**8))%256) + chr(i%256) + + server_address = '/home/flo/uds_socket' try: os.unlink(server_address) @@ -35,8 +41,13 @@ while True: if data: if data=="get\n": status, frame = cap.read() - print >>sys.stderr, 'sending image to the client' - connection.sendall(frame.tostring()) + framestr = frame.tostring() + lenframestr=len(framestr) + print hex(lenframestr) + for i in xrange(0,4): + print hex(ord(encode_int(lenframestr)[i])) + print 'sending ',lenframestr,' bytes to the client' + connection.sendall(encode_int(lenframestr)+framestr); cv2.imshow("img",frame) cv2.waitKey(20) else: |