-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientpython.py
37 lines (29 loc) · 900 Bytes
/
clientpython.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
import ast
def getOffersCoupons():
SERVER_IP = "localhost"
#SERVER_IP = '0.0.0.0'
PORT_NUMBER = 9988
SIZE = 1024
print(f"Server address: {SERVER_IP}:{PORT_NUMBER}")
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((SERVER_IP, PORT_NUMBER))
flag = True
#while flag:
# send
message = "sendData"
print(f"Send message: {message}")
client_socket.send(bytes(message, "utf-8"))
# receive
byte_message = client_socket.recv(SIZE)
message = byte_message.decode("utf-8")
print(f"Receive message: {message}")
print("\n\n",message,type(message))
message = message.replace("}{","},{")
message = "["+message+"]"
print(message)
data = ast.literal_eval(message)
print(data,type(data))
#flag = False
return data
#getOffersCoupons()