forked from thevibepei/pythonMultiProcessAndThreadExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_client.py
More file actions
32 lines (26 loc) · 851 Bytes
/
file_client.py
File metadata and controls
32 lines (26 loc) · 851 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import sys
if len(sys.argv) <= 1 :
print "Usage: ", sys.argv[0], "<file_your_wanna_sent>"
else:
print('Trying to connect...')
s = socket.socket()
s.connect(('127.0.0.1', 1234))
print('Connected. Wating for command.')
while True:
cmd = s.recv(32)
if cmd == 'getfilename':
print('"getfilename" command received.')
s.sendall(sys.argv[1])
if cmd == 'getfile':
print('"getfile" command received. Going to send file.')
with open(sys.argv[1], 'rb') as f:
data = f.read()
s.sendall('%16d' % len(data))
s.sendall(data)
print('File transmission done.')
if cmd == 'end':
print('"end" command received. Teminate.')
break