Last active
February 21, 2018 21:41
-
-
Save gbrennon/ae332f5a849bbc64965dcbeda7a7e639 to your computer and use it in GitHub Desktop.
Socket server - versao 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
HOST = '' | |
PORT = 5000 | |
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
orig = (HOST, PORT) | |
tcp.bind(orig) | |
tcp.listen(1) | |
while True: | |
con, cliente = tcp.accept() | |
# con -> send/receive cliente-> end do cliente | |
# print >>f,'Conectado por', cliente | |
con.send('Conectado!\n') | |
while True: | |
# print >>f, "Aguardando alarme..." | |
received = con.recv(100000) | |
if received: | |
print received | |
if "close" == received.rstrip(): | |
break | |
print 'Finalizando conexao', cliente | |
con.close() | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment