reprogramming

Discussion to talk about software related topics only.
SeeCwriter
Posts: 527
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post by SeeCwriter » Tue Dec 21, 2021 1:58 pm

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.

User avatar
pbreed
Posts: 1019
Joined: Thu Apr 24, 2008 3:58 pm

Re: reprogramming

Post by pbreed » Tue Dec 21, 2021 2:23 pm

link with wsock32.lib

SeeCwriter
Posts: 527
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post by SeeCwriter » Tue Dec 21, 2021 3:22 pm

Got an executable, followed your instructions and it works as advertised. I'll pass this along. Thanks again.
Sorry for being such a pain.

SeeCwriter
Posts: 527
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post by SeeCwriter » Tue Jan 11, 2022 10:59 am

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.

User avatar
pbreed
Posts: 1019
Joined: Thu Apr 24, 2008 3:58 pm

Re: reprogramming

Post by pbreed » Tue Jan 11, 2022 4:01 pm

So C/C++, Python, Go or Java?
Or the Linux wget utility?

SeeCwriter
Posts: 527
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post by SeeCwriter » Wed Jan 12, 2022 8:14 am

Python, please.

User avatar
pbreed
Posts: 1019
Joined: Thu Apr 24, 2008 3:58 pm

Re: reprogramming

Post by pbreed » Thu Jan 13, 2022 12:51 pm

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)

SeeCwriter
Posts: 527
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post by SeeCwriter » Thu Jan 13, 2022 2:18 pm

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.

User avatar
pbreed
Posts: 1019
Joined: Thu Apr 24, 2008 3:58 pm

Re: reprogramming

Post by pbreed » Fri Jan 14, 2022 5:20 am

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')
.
.
.

Post Reply