-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientThreaded.py
59 lines (44 loc) · 941 Bytes
/
clientThreaded.py
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
import socket
import string
import sys
import pdb
## conver string to integer
def convertNum(s):
try:
return int(s)
except ValueError:
return 0
host = sys.argv[1]
filename = sys.argv[2]
print host
print filename
#for i in xrange(1, total):
# a += str(sys.argv[i])
address = (host,22085)
mySocket = socket.socket()
mySocket.connect(address)
print("Connected successfully!")
# send fileName
mySocket.send(filename)
print "Requested file : " + filename
cont = False
blockSize = mySocket.recv(1024)
if convertNum(blockSize) != 0:
print "Received blockSize:", blockSize
blockSize = convertNum(blockSize)
cont = True
else:
print blockSize
cont = False
if cont:
data = []
for x in xrange(0, blockSize):
data.append(mySocket.recv(1024))
print "File received and saved to ", filename
mySocket.close()
file = open(filename, "wr")
for i in range(0, blockSize):
file.write(data[i])
file.close()
else:
pass