Untitled

 avatar
unknown
plain_text
2 years ago
685 B
4
Indexable
#client program for chat
import socket

def client_program():
    #get the hostname
    host = socket.gethostname()
    port = 5000 # initiate port number above 1024

    client_socket = socket.socket() #get instance
    client_socket.connect((host, port)) #bind host addr and port together

    message = input(' -> ') #take input

    while message.lower().strip() != 'bye':
       client_socket.send(message.encode())
       data = client_socket.recv(1024).decode()

       print('Received from server: '+data)

       message = input(' -> ') #again take input

    client_socket.close() #close the connection

if __name__ == '__main__':
    client_program()
Editor is loading...