-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathServer.py
31 lines (25 loc) · 981 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
# -*- coding:utf-8 -*-
import sys
from sender import *
from receiver import *
# data : 'LFTP lget myserver mylargefile'
# data : 'LFTP lsend myserver mylargefile'
def send(hostAddr, dstAddr, filePath):
sender(hostAddr, dstAddr, filePath, 'server').createSender()
def receive(hostAddr, dstAddr, filePath):
receiver(hostAddr, dstAddr, filePath, 'server').createReceiver()
if __name__ == "__main__":
# 服务端监听请求
hostPort = 21567
udpSock = socket(AF_INET, SOCK_DGRAM) # 绑定socket
udpSock.bind(('', hostPort))
print('Bind udp on', hostPort)
# 服务端从客户端接收数据
while 1:
hostPort += 10
data, dstAddr = udpSock.recvfrom(MSS)
temp = data.decode().split(DELIMITER)
if temp[0] == 'lget':
Thread(target=send, args=(('', hostPort), dstAddr, temp[1])).start()
elif temp[0] == 'lsend':
Thread(target=receive, args=(('', hostPort), dstAddr, temp[1])).start()