PART-2: SENDING FILE INTO CLIENT SYSTEM FROM SERVER USING SOCKET IN PYTHON

Ashish Pratap Singh
3 min readSep 27, 2021

--

Hello readers in the previous article of PART-1: CLIENT-SERVER CONNECTION USING SOCKET IN PYTHON, I have showed you that how to successfully make a connection between client and server as well as sending some messages from server side to client. Today I’m telling you that how to send some files to the client system from server system.

Sending file from SERVER to CLIENT

Before going forward you have to understand that why you want to send file from the server to the client system?
You can use this method when you have a connection between client-server and you are getting a lot of data from server side and you need to store all the data at a specific location, in this case you should create a directory into the client system and where all the server data will be download. So once the server will upload the data then the socket helps to download that data into the client system.

FUNCTION AT SERVER SIDE

1: Create a function that collect all the data from server and call the another function that used to send file at client side.

2: After collection all data, the socket.client_conn.send() function will used to send the data.

FUNCTION AT CLIENT SIDE

3: Once the server sent the data, now we create a function at client side that accept the data and will download that data into the client specific directory.

4: The client will use socket.recv() function that receive the incoming data and write the data at defined directory.

This 4 steps used to upload the file from the server system and download the file into the client system using socket.

This is part-2 of the client-server connection. you can get the code on GitHub.

HOW TO RUN: In this you’ll get two main file:
1: mainServer.py
2: mainClient.py

To run this code you first need to run the mainServer.py file so that the server-side person is ready for the incoming connection from the client-side and as the client runs the mainClient.py file the server will make a successful connection and send the encoded messages to the client. Thanks for reading this article. Please clap if you like this article.

--

--

No responses yet