Advertisement
lucasmnds

cliente

May 27th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. # Echo client program
  3. import socket
  4.  
  5. HOST = '127.0.0.1'    # The remote host
  6. PORT = 50007              # The same port as used by the server
  7. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #IPv4,tipo de socket
  8. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  9. s.connect((HOST, PORT))  #Abre uma conexão com IP e porta especificados
  10. print "Conectou"
  11. s.sendall('Hello, world') #Envia dados
  12. print "Enviou e está esperando receber"
  13. data = s.recv(1024) #Recebe dados
  14. s.close() #Termina conexão
  15. print "Fechou a conexão"
  16. print 'Received', repr(data) #Imprime o que recebeu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement