Advertisement
Guest User

Code

a guest
Apr 7th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. Server Code:
  2. import socket
  3.  
  4. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  5. s.bind((socket.gethostname(), 5050))
  6. s.listen()
  7.  
  8. while True:
  9.     clientsocket, address = s.accept()
  10.     print(f'Connetion from {address} has been established!')
  11.     clientsocket.send(bytes('Welcome to the server!', 'utf-8'))
  12.  
  13. Client Code:
  14.  
  15. import socket
  16.  
  17. HOST = socket.gethostbyname(socket.gethostname())
  18. PORT = 5050
  19.  
  20. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  21. s.connect((HOST, PORT))
  22.  
  23. msg = s.recv(1024)
  24. print(msg.decode('utf-8'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement