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() '''
6/21/2018 11:12:25 AMhex
1 AnswerNew Answer
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.