Advertisement
Guest User

client

a guest
Mar 30th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1.  
  2. import socket
  3.  
  4.  
  5. def client_program():
  6.     host = socket.gethostname()  # as both code is running on same pc
  7.     port = 80  # socket server port number
  8.  
  9.     client_socket = socket.socket()  # instantiate
  10.     client_socket.connect(("socket-alibot.fandogh.cloud", port))  # connect to the server
  11.     data = client_socket.recv(1024)
  12.     print( data)
  13.     message = input(" -> ")  # take input
  14.    
  15.     while message.lower().strip() != 'bye':
  16.         client_socket.send(message.encode())  # send message
  17.         data = client_socket.recv(1024).decode()  # receive response
  18.  
  19.         print('<--' + data)  # show in terminal
  20.  
  21.         message = input(" -> ")  # again take input
  22.  
  23.     client_socket.close()  # close the connection
  24.  
  25. if __name__ == '__main__':
  26.     client_program()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement