Skip to content

Instantly share code, notes, and snippets.

@gbrennon
Last active February 21, 2018 21:41
Show Gist options
  • Save gbrennon/ae332f5a849bbc64965dcbeda7a7e639 to your computer and use it in GitHub Desktop.
Save gbrennon/ae332f5a849bbc64965dcbeda7a7e639 to your computer and use it in GitHub Desktop.
Socket server - versao 2
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