-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientUDP.py
More file actions
68 lines (42 loc) · 1.55 KB
/
clientUDP.py
File metadata and controls
68 lines (42 loc) · 1.55 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
56
57
58
59
60
61
62
63
64
65
66
67
68
'''
Created on Jan 17, 2020
@author: tiz
'''
from socket import *
import sys
serverName = 'localhost'
serverPort = 4000
clientSocket = socket(AF_INET, SOCK_DGRAM)
#clientSocket.connect((serverName,serverPort))
fileToget = raw_input('Url to get :')
#clientSocket.send(fileToget)
clientSocket.sendto(fileToget,(serverName, serverPort))
try:
#fileSizeFromServer = int(clientSocket.recv(4000))
fileSizeFromServer, serverAddress = clientSocket.recvfrom(2048)
if 'Error' in fileSizeFromServer:
print "Error, the Server was unable to get the file"
clientSocket.close()
sys.exit(1)
except ValueError:
print "Error, the Server was unable to get the file"
sys.exit(1)
#fileFromServer = clientSocket.recv(4000)
fileFromServer, serverAddress = clientSocket.recvfrom(2048)
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
fileSizeFromServerInt = int(fileSizeFromServer)
if fileSizeFromServerInt == 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')
clientSocket.sendto('BYE',(serverName, serverPort))
#timeToDwFromServer = clientSocket.recv(4000)
timeToDwFromServer, serverAddress = clientSocket.recvfrom(2048)
print 'Time to download the file is: ', timeToDwFromServer, ' sec.'
clientSocket.close()