forked from cmattey/language_learning_app_hci
-
Notifications
You must be signed in to change notification settings - Fork 2
/
socket_class.py
45 lines (40 loc) · 1.16 KB
/
socket_class.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
import socket
class SocketClass():
def __init__(self, host, port):
self.listening = True
self.host = host
self.port = port
self.allDataReceived = []
self.my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
"""
A function that opens a socket with Matlab PC
"""
def open_socket(self):
try:
self.my_socket.connect((self.host, self.port))
return True
except Exception as e:
print("Error creating socket, %s" % str(e))
return False
"""
function that sends data throught the socket to Matlab PC
"""
def send_data(self, data):
try:
self.my_socket.sendall(data.encode('utf-8')) # send marker data to Matlab PC
except Exception as e:
print(e)
"""
Get method that returns allDataRecieved list
"""
def get_all_data_received (self):
return self.allDataReceived
"""
A function that closes the socket
"""
def close_socket(self):
try:
self.listening = False
self.my_socket.close()
except Exception as e:
print(e)