Advertisement
ZalaScript

Socket Client/Server Py

May 6th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import socket
  2.  
  3.  
  4. ### SERVIDOR ###
  5.  
  6. mi_socket = socket.socket()
  7. mi_socket.bind(('localhost','8000'))
  8. mi_socket.listen(5)
  9.  
  10. while True:
  11.     conexion, addr = mi_socket.accept()
  12.     print("Nueva Conexion Establecida: ", addr)
  13.    
  14.     conexion.send("Conexion establecida con el servidor")
  15.     conexion.close()
  16.  
  17.  
  18. ### CLIENTE ###
  19.  
  20. mi_socket = socket.socket()
  21. mi_socket.connect(('localhost',8000))
  22. mi_socket.send("Hola desde el cliente")
  23. respuesta = mi_socket.recv(1024)
  24. print(respuesta)
  25. mi_socket.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement