summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.c14
-rw-r--r--server.py15
2 files changed, 27 insertions, 2 deletions
diff --git a/client.c b/client.c
index c0198c0..a97d810 100644
--- a/client.c
+++ b/client.c
@@ -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;
}
diff --git a/server.py b/server.py
index 7eb5ef7..819d88d 100644
--- a/server.py
+++ b/server.py
@@ -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: