28 lines
435 B
Python
28 lines
435 B
Python
|
#!/usr/bin/python2
|
||
|
|
||
|
import socket
|
||
|
import thread
|
||
|
|
||
|
host = socket.gethostname()
|
||
|
port = 5005
|
||
|
|
||
|
def handler(client, addr):
|
||
|
while True:
|
||
|
data = client.recv(1024)
|
||
|
if not data:
|
||
|
break
|
||
|
print addr, ": ", data
|
||
|
|
||
|
def main():
|
||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||
|
s.bind((host,port))
|
||
|
s.listen(5)
|
||
|
|
||
|
while 1:
|
||
|
client, addr = s.accept()
|
||
|
thread.start_new_thread(handler, (client, addr))
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|
||
|
|