-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendingNumpy.py
More file actions
48 lines (37 loc) · 1 KB
/
Copy pathsendingNumpy.py
File metadata and controls
48 lines (37 loc) · 1 KB
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
'''
import socket, json, pickle
PORT = 12345
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("10.40.3.2", PORT))
#while True:
arr = ([1],[1])
data_string = pickle.dumps(arr)
s.send(data_string)
s.send(data_string)
s.send(data_string)
s.send(data_string)
s.close();
'''
import socket,json
import time
import numpy as np
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("10.40.3.2", 8220))
class NumpyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
return json.JSONEncoder.default(self, obj)
data = np.array([1,1])
#for index in xrange(5):
#data = "GET\nSONAR%d\n\n" % index
print 'send to server: ',data
client_socket.send(json.dumps({'data': data}, cls=NumpyEncoder))
while client_socket.recv(2048) != "ack":
print "waiting for ack"
print "ack received!"
#send disconnect message
dmsg = "disconnect"
print "Disconnecting"
client_socket.send(dmsg)
client_socket.close()