reprogramming

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

Re: reprogramming

Post 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.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: reprogramming

Post by pbreed »

link with wsock32.lib
SeeCwriter
Posts: 606
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post 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.
SeeCwriter
Posts: 606
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post 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.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: reprogramming

Post by pbreed »

So C/C++, Python, Go or Java?
Or the Linux wget utility?
SeeCwriter
Posts: 606
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post by SeeCwriter »

Python, please.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: reprogramming

Post 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)
SeeCwriter
Posts: 606
Joined: Mon May 12, 2008 10:55 am

Re: reprogramming

Post 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.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: reprogramming

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