Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e50ccc6

Browse files
committed
tcp服务
1 parent 036e436 commit e50ccc6

File tree

3 files changed

+43
-196
lines changed

3 files changed

+43
-196
lines changed

pytcp/TcpServer.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import time
2+
from socket import *
3+
4+
import lighton
5+
6+
lighton.setUP()
7+
8+
ctrCmd = ['UP', 'DOWN', 'VIEW']
9+
message = "hello world"
10+
HOST = '192.168.43.96'
11+
PORT = 5555
12+
13+
BUFSIZE = 1024
14+
ADDR = (HOST, PORT)
15+
16+
tcpSerSock = socket(AF_INET, SOCK_STREAM)
17+
tcpSerSock.bind(ADDR)
18+
tcpSerSock.listen(5)
19+
20+
while True:
21+
tcpCliSock, addr = tcpSerSock.accept()
22+
23+
time.sleep(.05)
24+
data = ''
25+
data = tcpCliSock.recv(BUFSIZE).decode()
26+
27+
print(data)
28+
29+
if not data:
30+
print("there is no data")
31+
break
32+
33+
if data == ctrCmd[0]:
34+
lighton.ledOn()
35+
36+
if data == ctrCmd[1]:
37+
lighton.ledOff()
38+
39+
if data == ctrCmd[2]:
40+
lighton.ledOn()
41+
# here I want to send String back to Android
42+
43+
tcpCliSock.close();

pytcp/multithreadedClient.py

Lines changed: 0 additions & 106 deletions
This file was deleted.

pytcp/multithreadedServer.py

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)