Hello MicroPython community,
Just playing with socket module using esp8266, I wrote a little script to transfer file from computer to esp board and I faced a problem. So as I understood here is the problem to write binary to a file, the error appears:
Traceback (most recent call last):
File "<stdin>", line 27, in <module>
File "<stdin>", line 23, in start_deamon
File "<stdin>", line 23, in start_deamon
OSError: 28
and here is my code:
server side will listen and receive the file
import socket
import sys
localhost = ("0.0.0.0", 37641)
def start_deamon():
s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR, 1)
s.bind(localhost)
s.listen(5) # allow listening
while True:
conn, addr = s.accept()
print('Got connection from', addr)
data = conn.recv(1024)
with open('received_file', 'wb') as f:
f.write(data)
f.close()
s.close()
start_deamon()
and client will send file
#!/usr/bin/env python3
import socket
import sys
remotehost = ("192.168.1.194", 37641)
def file_transfer():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.connect(remotehost)
f = open(sys.argv[1], 'rb')
data = f.read(1024)
s.sendall(data)
f.close()
s.close()
if __name__ == "__main__":
file_transfer()
Here is simple file transfer script, tried to find the solution in off sources but no luck to solve it, so if some one could help me I would really appreciate. Thank you in advance!
P.S. sorry BBCode is off and i can't do anything with that.