-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.py
63 lines (49 loc) · 1.42 KB
/
client.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
import socketio
import sys
from os import environ
slot_to_open = "100"
class socket_sender:
# init
sio = socketio.Client()
# init server ip
#ip = 'http://35.246.29.217:65080/'
ip='http://35.246.29.217:65080/'
#slot_to_open = "0"
def __init__(self):
#sio = socketio.Client()
self.sio.connect(self.ip)
def get_slot(self):
global slot_to_open
return slot_to_open
def set_slot(self, data):
self.slot_to_open = data
# connect to server
@sio.on('connect')
def on_connect():
print('connection established')
#sio.emit(getTopic(),getMsg())
# client receiver
@sio.on('slot_to_open')
def on_message(data):
global slot_to_open
slot_to_open = data
print('message received with ', slot_to_open)
#sio.emit('my response', {'response': 'my response'})
@sio.on('disconnect')
def on_disconnect():
print('disconnected from server')
# not used...
def connect_to_server(self):
print('connect function...')
print(self.ip)
self.sio.connect(self.ip)
self.sio.wait()
def getMsg():
return msg
def getTopic():
return topic
# function to send msg to server
def sendMsg(self, topic, msg):
self.sio.emit(topic, msg)
self.sio.sleep(0.5)
#sio.disconnect()