example tcp socket server
This commit is contained in:
commit
4aa84b02bf
27
tcp_socket_server.py
Executable file
27
tcp_socket_server.py
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
#!/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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user