-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
25 lines (18 loc) · 766 Bytes
/
client.py
File metadata and controls
25 lines (18 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import socket
def client_program():
host = socket.gethostname() # as both code is running on same pc
port = 5000 # socket server port number
client_socket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM) # instantiate
client_socket.connect((host, port)) # connect to the server
print("Client with IP and port : ", host, port)
message = input("send message -> ")
while message.lower().strip() != '/':
client_socket.send(message.encode())
data = client_socket.recv(1024).decode()
print('Received from server : ', host, " : " + data)
message = input("send message -> ")
print("waiting for message.....")
client_socket.close()
if __name__ == '__main__':
client_program()