-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
55 lines (34 loc) · 1.08 KB
/
client.py
File metadata and controls
55 lines (34 loc) · 1.08 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
52
53
54
55
'''
Created on Jan 17, 2020
@author: tiz
'''
from socket import *
import os.path
from os import path
import sys
serverName = 'localhost'
serverPort = 4000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
fileToget = raw_input('Url to get :')
clientSocket.send(fileToget)
try:
fileSizeFromServer = int(clientSocket.recv(4000))
except ValueError:
print "Error, the Server was unable to get the file"
sys.exit(1)
fileFromServer = clientSocket.recv(4000)
print 'From Server:', fileFromServer
#Check the size of the file downloaded
fileSize = int (os.path.getsize(fileFromServer))
print 'File size downloaded from server: ', fileSize
#Compare size of the file with info coming from the server
if fileSizeFromServer == fileSize:
print 'File arrived ..sending BYE to server'
else:
print 'Files have not the same size: something wrong. Exiting'
sys.exit(1)
clientSocket.send('BYE')
timeToDwFromServer = clientSocket.recv(4000)
print 'Time to download the file is: ', timeToDwFromServer, ' sec.'
clientSocket.close()