-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
44 lines (37 loc) · 972 Bytes
/
server.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
from socket import *
import argparse
from time import ctime
print("TCP server starts")
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'--ip', '-i',
default="10.0.0.1",
dest='ip',
help='IP address of server.')
args = parser.parse_args()
return args
args = parse_args()
# HOST = ''
HOST = args.ip
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST,PORT)
tcpSerSock = socket(AF_INET,SOCK_STREAM)
tcpSerSock.bind(ADDR)
tcpSerSock.listen(5)
while True:
print('waiting for connection...')
tcpCliSock, addr = tcpSerSock.accept()
print('...connnecting from:', addr)
while True:
data = tcpCliSock.recv(BUFSIZ)
if data == "byebye":
break
# if not data:
# break
#tcpCliSock.send('[%s] %s' %(bytes(ctime(),'utf-8'),data))
# tcpCliSock.send(('[%s] %s' % (ctime(), data)).encode())
tcpCliSock.close()
break
tcpSerSock.close()