forked from kevinkit/Camera2TCP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientC.py
82 lines (65 loc) · 1.79 KB
/
clientC.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 15 20:52:38 2017
@author: kevin
This is a simple client for getting HD-RGB data from the Kinect v2
DOES NOT WORK :(
"""
# Python TCP Client A
import socket
import numpy as np
import cv2
import binascii
import time
host = socket.gethostbyname(socket.gethostname())
port = 2004
BUFFER_SIZE = 305280
MESSAGE_ASK = "Connecting2KinectSkeleton"
MESSAGE = "KinectSkeleton"
tcpClientA = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpClientA.connect((host, port))
#Send request
while True:
try:
print("trying on " + str(host))
tcpClientA.send(MESSAGE_ASK);
data = tcpClientA.recv(BUFFER_SIZE)
except Exception:
print data
print("host unreachable...will...try..to..connect again");
continue;
# shaping = data.split(',')
print data
# print shaping
buf = int(data)*2000;
break;
print("Buffer size: " + str(BUFFER_SIZE));
while True:
print("trying")
t0 = time.time()
tcpClientA.send(MESSAGE)
print("message was send")
try:
print("waiting...")
data = tcpClientA.recv(BUFFER_SIZE)
print("recieving data")
except Exception:
print("host unreachable...will try...forever...")
continue;
print ("Recieved data len: " + str(len(data)))
print data
temp = str(np.frombuffer(data,dtype=np.uint8))
print temp
# print data
# if data != "no frame":
# img = np.frombuffer(data,dtype=np.uint8).reshape((int(shaping[0]),int(shaping[1]),int(shaping[2])))
# t1 = time.time()
#
# print("FPS: " + str(1/(t1-t0)))
## if (float(t1) - float(t0)) < 1./30:
## continue;
#
# cv2.imshow('something',img)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
tcpClientA.close()