-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient2.py
More file actions
37 lines (28 loc) · 950 Bytes
/
client2.py
File metadata and controls
37 lines (28 loc) · 950 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
27
28
29
30
31
32
33
34
35
36
37
# Socket programming - Client side program
import socket
import sys
def Main():
# setting host to local host and defining a port number
host = '127.0.0.1'
port = 22796
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# connecting server to host
sock.connect((host,port))
print('\n Type quit to exit')
while True:
# request message from client
print('\n Print message')
message = input()
if (message == 'quit'):
sock.close()
sys.exit()
# the message is sent to the server
sock.send(message.encode('ascii'))
# server must receive the message
data = sock.recv(1024)
# print the reversed string received message
print('Message as received from the server :',str(data.decode('ascii')))
# close the connection
sock.close()
if __name__ == '__main__':
Main()