-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
26 lines (16 loc) · 873 Bytes
/
client.py
File metadata and controls
26 lines (16 loc) · 873 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
26
import socket
def client_program():
host = '------' # as both code is running on same pc
port = 5018 # socket server port number
##### a different port number should be used for each connection ####
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # instantiate-take a case.
client_socket.connect((host, port)) # connect to the server
message = input(" -> ") # take terminal input
while message.lower().strip() != 'bye': #bye :(
client_socket.send(message.encode()) # send message :)
readata = client_socket.recv(1024).decode() # receive response
print('Received from anonymous: ' + readata) # show in terminal
message = input(" -> ") # again take input
client_socket.close() # close the connection-leave the connection :)
if __name__ == '__main__':
client_program()