-1

I'm just new to Python Socket~

I'm making a socket project which can send a file to the server, and I would like to make to client execution like so:

python client.py [hostname] [port] [send filename]

sys.argv[1], sys.argv[2] are used to send hostname & port to the socket.recv(), but how can the server recognise the filename/third argument?

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
Sai
  • 9
  • 1
    You cannot send "files". You only can send data, i.e. bytes. These data need to contain the content of the file. If you want to make the server aware of the original filename you need to send the filename too as data. – Steffen Ullrich Oct 26 '19 at 18:51
  • it's fixed :) thanks~ – Sai Oct 26 '19 at 20:11

1 Answers1

0

I will tell you how but one thing:

There isn't code shown which you tried. In code I mean Python script.

In socket module there is option to send files, called socket.sendfile(file, offset=0, count=None) and it is option to send files via socket.

See documention for more details.

Latest stable 3x (3.8) Click Here

Latest stable 2x (2.7) Click Here

UltraStudioLTD
  • 300
  • 2
  • 14