Advertisement
noonarhz

client.py

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