Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket;
- # /home/a221251782/Monitoramento/
- BACKUPFILEPATH = 'log-backup.log'
- SERVERHOST = 'localhost';
- SERVERPORT = 8191;
- def startserver():
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
- SERVERTUPLE = (SERVERHOST, SERVERPORT);
- server.bind(SERVERTUPLE);
- server.listen();
- print(f'LISTENING AT {SERVERHOST}:{SERVERPORT}');
- while True:
- conn, addr = server.accept();
- with conn:
- data = conn.recv(4096).decode();
- if data:
- with open(BACKUPFILEPATH, 'a') as fh:
- fh.write(f'{data}\n');
- #with:
- print(f'APPENDED FROM {addr}');
- #if:
- #with:
- #while:
- #with:
- #def:
- if __name__ == '__main__': startserver();
Advertisement
Add Comment
Please, Sign In to add comment