-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor_pi.py
37 lines (26 loc) · 1015 Bytes
/
for_pi.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
import socket
def client_program():
#host = socket.gethostname() # as both code is running on same pc
host = '192.168.43.31'
port = 5015 # socket server port number
client_socket = socket.socket() # instantiate
client_socket.connect((host, port)) # connect to the server
#message = input(" -> ") # take input
key = input()
while key.lower().strip() != 'exit':
if key == 'w':
message = "1,1,255,255"
if key == 'a':
message = "1,2,255,255"
if key == 's':
message = "2,2,255,255"
if key == 'd':
message = "2,1,255,255"
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
key = input()
client_socket.close() # close the connection
if __name__ == '__main__':
client_program()