-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradio_streaming_PC_epy_module_client.py
69 lines (57 loc) · 2.57 KB
/
radio_streaming_PC_epy_module_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
64
65
66
67
68
69
# this module will be imported in the into your flowgraph
import socket
def client(tt):
while True:
# Storage variables initial values
test_variable = "False"
# Try to connect
host = '192.168.137.8'
port = 4242
client_socket = socket.socket()
client_socket.connect((host, port))
if(client_socket.getsockname()[0] != "0.0.0.0"):
# Connected
print("Connected to server")
while True:
# Check if variables have change
# print(tt.get_stream_variable())
# if(tt.get_stream_variable() != test_variable):
if(tt.get_stream_variable() == "True"):
tt.set_stream_variable("False")
# print(tt.get_stream_variable())
print("sending message")
# test_variable = tt.get_stream_variable() # Store current value
# message_ = "test!"
client_socket.send(tt.get_station().encode())
# client_socket.close()
# def client(tt):
# while True:
# # with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
# # print(testing)
# # s.connect(('192.168.137.8', 4242))
# # if(testing != ""):
# # print(testing)
# # # s.sendall(b'Hello, world')
# # # s.sendall(b'{}'.format(station + ">"))
# # s.send(testing.encode())
# # data = s.recv(1024)
# # print('Received', repr(data))
# # print(testing)
# # testing=""
# host = '192.168.137.8'
# port = 4242 # socket server port number
# client_socket = socket.socket() # instantiate
# print(client_socket.getpeername())
# client_socket.connect((host, port)) # connect to the server
# # if(client_socket.raddr):
# # print("conncted")
# print(client_socket.getpeername())
# message = "test..." # take input
# # print(tt.get_stream_variable())
# # while tt.get_stream_variable() == 'True':
# # print("sending message")
# client_socket.send(message.encode()) # send message
# data = client_socket.recv(1024).decode() # receive response
# # print('Received from server: ' + data) # show in terminal
# # message = input(" -> ") # again take input
# # client_socket.close() # close the connection