blob: a7be5c182391a0d8797209e2e2e9abe31e0e69f1 (
plain)
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
|
import os
import sys
import time
import socket
from threading import Thread
HOST = ''
PORT = 80
Users = {}
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST,PORT))
x = 0
#The thread that listens and writes to file
def conCurr(conn,addr):
print("Starting thread for address: " + str(addr))
f = open("./logs/" + str(addr).replace(".","_") + ".txt",'a')
while(True):
try:
data = conn.recv(5)
except:
f.close()
print("Client disconnected.")
return
data = data.decode('UTF-8','ignore')
data = ''.join(data.split())
f.write(data)
while(True):
if(True):
s.listen(1)
conn,addr = s.accept()
thre = Thread(target = conCurr, args=(conn,addr,)).start()
x = x+1
|