0

Python3 code-help

Hey guys i'm writing a server that will send data/a picture or any files to the client and client will receive the data and save them. I can't find much info on sending files via sockets and saving them etc...anyone got any good instructions on sending files via socket? #SERVER FILE ''' import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) port = 5478 s.bind(('', port)) print('done binding') s.listen(5) print("listening incoming") while True: try: c, addr = s.accept() print('accepted the incoming drom:', addr) inpa = input("select the file you want to send -> ") file = open(inpa, "wb") c.send(file) print("file sending to:", addr) except SyntaxError: print("something wrong in while loop") s.close() s.close() ''' #CLIENT FILE ''' import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) port = 5478 s.connect(('127.0.0.1', port)) data = s.recv(1024).decode() savedata = open(data, "wb") print("data should be saved now") s.close() '''

21st Jun 2018, 11:12 AM
hex
hex - avatar
1 Resposta
0
so idk if i shall encode/decode a file as i need to do with text. i'm not sure if "open" command is the right way to save it with "wb" -web binary if im not totally wrong and how to set up the .recv() command so that it would allow more then 1024 bits. If i don't put an amount in it at all it wont work.
21st Jun 2018, 11:15 AM
hex
hex - avatar