python socket send big data

Solutions on MaxInterview for python socket send big data by the best coders in the world

showing results for - "python socket send big data"
Yannik
26 May 2017
1# Client Side Program (Sender)
2import socket
3
4data = b"hsfbhdhfbjsnkdfkkn" * 1000  # Very Big Data to send
5
6server = ('127.0.0.1', 8000)
7
8s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9s.connect(server)
10
11block_size = 1000
12block_number = 0
13block_data = b''
14
15while True:
16  # Selected block to send
17  block_data = data[block_number * block_size: (block_number + 1) * block_size]
18  
19  s.send_all(block_data)
20  
21  if not block_data:
22    break
23  
24  block_number += 1
25s.close()