-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
51 lines (39 loc) · 1.04 KB
/
client.py
File metadata and controls
51 lines (39 loc) · 1.04 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
""" Assignment 2
Computer Networks
client.py
"""
import socket
#constants
port = 12345
tosend = 'check.py'
torec = 'cli_file_recv.xz'
host = socket.gethostname() #Change to sever IP Address if different systems on same network
#Creating a socket and connecting to server
s = socket.socket()
s.connect((host, port))
#opening file to send
f = open(tosend,'rb')
#Sending file to compress
print ('\n Sending file to compress...')
pack = f.read(1024)
while(pack):
print ('Sending file to compress...')
s.send(pack)
pack = f.read(1024)
f.close()
print ("Done Sending file to compress")
#Shutting down the sending capabilities of client socket
s.shutdown(socket.SHUT_WR)
#Opening a new file to recieve the compressed file
f = open(torec,'wb')
print ("\n Receiving compressed file...")
#Recieving the compressed file
pack = s.recv(1024)
while(pack):
print ("Receiving compressed file...")
f.write(pack)
pack = s.recv(1024)
f.close()
print ("Done Receiving compressed file")
# Closing the socket
s.close()