-
Notifications
You must be signed in to change notification settings - Fork 0
/
TCPserver.py
38 lines (29 loc) · 868 Bytes
/
TCPserver.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
from socket import *
import types
port = 11111
host = ''
ADDR = (host, port)
BUFSIZ = 2048
tcpSocket = socket(AF_INET, SOCK_STREAM)
tcpSocket.bind(ADDR)
tcpSocket.listen(5)
while True:
print('waiting for connection...')
clientSocket, clientAddr = tcpSocket.accept()
print('conneted from: %s' %clientAddr[0])
clientSocket.send('connected succefully'.encode('utf-8'))
while True:
try:
data = clientSocket.recv(BUFSIZ)
except IOError as e:
print(e)
clientSocket.close()
break
if not data:
break
returnData = data.decode('utf-8')
print('receive: ',returnData)
str = input('Input what you want to send: ')
clientSocket.send(str.encode('utf-8'))
clientSocket.close()
tcpSocket.close()