Page 2 of 2
Re: reprogramming
Posted: Tue Dec 21, 2021 1:58 pm
by SeeCwriter
I don't have a TcpSendFile executable, just a source file. I tried to compile the source code with Visual Studio. It created an object file but threw 8 linker errors, so no executable.
Re: reprogramming
Posted: Tue Dec 21, 2021 2:23 pm
by pbreed
link with wsock32.lib
Re: reprogramming
Posted: Tue Dec 21, 2021 3:22 pm
by SeeCwriter
Got an executable, followed your instructions and it works as advertised. I'll pass this along. Thanks again.
Sorry for being such a pain.
Re: reprogramming
Posted: Tue Jan 11, 2022 10:59 am
by SeeCwriter
About 3-posts back pbreed said "Tell me the platform and their dev environment and I'll make you an example." The end user would like to get the example program if that offer is still available. They run Linux on a dual-core ARM processor.
Re: reprogramming
Posted: Tue Jan 11, 2022 4:01 pm
by pbreed
So C/C++, Python, Go or Java?
Or the Linux wget utility?
Re: reprogramming
Posted: Wed Jan 12, 2022 8:14 am
by SeeCwriter
Python, please.
Re: reprogramming
Posted: Thu Jan 13, 2022 12:51 pm
by pbreed
I'm not a real python programmer, this works but the python gurus could probably do this in half the code.
I tested with python 3.8
import socket
import sys
PORT = 20034 # The port used by the server
argv=len(sys.argv)
if (len(sys.argv)<3):
print("Too few arguments\n")
print('usage is: python nbupdate.py <ipaddress> filename')
exit(-1)
HOST=sys.argv[1]
print('sending ',sys.argv[2],' to ',HOST)
try:
f = open(sys.argv[2], 'rb')
binarycontent = f.read(-1)
if not binarycontent:
print('Failed to read file')
exit(-1)
except IOError:
print('Error While Opening the file!')
print('Read',len(binarycontent),' bytes from file')
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.settimeout(5) #5 seconds
s.connect((HOST, PORT))
except socket.error as err:
print('Socket connection error:',str(err))
exit(-1)
try:
s.sendall(b'POST /appupdate.html\r\n\r\n')
s.sendall(binarycontent)
data = s.recv(1024)
except socket.error as err:
print('Socket send error:',str(err))
exit(-1)
if(data.find(b'200\r\n')>0):
print('Success')
exit(0)
print('Error Received Result:', repr(data))
exit(-1)
Re: reprogramming
Posted: Thu Jan 13, 2022 2:18 pm
by SeeCwriter
I tried the script and I get error: "Socket send error: timed out". Is this timeout related to the 5-second timeout set earlier?
Edit: Even though I got the timeout error, the module reprogrammed successfully.
Edit 2: Changing the timeout from 5-seconds to 30-seconds removes the error. It works great.
Thank you.
Re: reprogramming
Posted: Fri Jan 14, 2022 5:20 am
by pbreed
The five seconds was the connection timeout....
I tested on a local LAN.
That is in there so if you give it a wrong IP address it does not just hang...
So probably should reset the timeout going from the connect to the send...
So rather than change the 5 second before the connect...
Change it to 30 or 60 just before the first sendall.....
IE:
s.settimeout(60)
s.sendall(b'POST /appupdate.html\r\n\r\n')
.
.
.