-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_design.py
45 lines (38 loc) · 1.11 KB
/
socket_design.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
import _thread
import time
host = '127.0.0.1'
port = 9000
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
def recv(x):
data2 = ""
print(x)
while True:
# server'dan gelen veriyi tutan degisken ------------
data2 = sock.recv(1024).decode()
if not data2: sys.exit(0)
if "embedded" not in data2:
if "Client has connected" not in data2:
print(data2)
def sendData(msg):
data = "embedded: "
counter = 1
while 1:
sockSender = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockSender.connect((host, port))
# server'a veri gönderen değisken ----------
data += str(counter)
counter += 1
# data'nın yollandıgı satir -----------
sockSender.send(data.encode())
sockSender.close()
time.sleep(.01)
try:
_thread.start_new_thread(recv, (12, ))
_thread.start_new_thread(sendData, ('msg', ))
except:
print("Error: unable to start thread")
while 1:
pass
sock.close()