-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpushserver.py
More file actions
34 lines (28 loc) · 748 Bytes
/
pushserver.py
File metadata and controls
34 lines (28 loc) · 748 Bytes
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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
from multiprocessing import Process
import os
import socket
import fileinput
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('10.3.45.144',2333))
s.listen(1)
def write(sock,addr):
print('connect from %s'%addr[0])
filename=sock.recv(1024).decode('utf-8')
textfile=open('./%s'%filename,'w')
while True:
data=sock.recv(1024).decode('utf-8')
if data=='over':
sock.send(b'get it')
break
textfile.write('%s'%data)
print('successful receive from %s'%addr[0])
textfile.close()
sock.close()
quit()
print('waiting...')
while True:
sock,addr=s.accept()
p=Process(target=write,args=(sock,addr))
p.start()