Using PropTCP to fetch data from remote servers
Nick McClick
Posts: 1,003
I'm trying to get PropTCP to grab data from a remote server - my idea is to use a php script to process some data and give the prop some simple output that it can grab from the server via http. I can get PropTCP running harrison's ajax server demo fine, but the problem comes when connecting to a remote server. First, here's the relevant code;
I setup 2 sockets to listen on port 88.
These guys run in a loop & will display the results of sock[noparse][[/noparse] 3 ]. I can get them to display browser request headers just fine.
The part that I think is broken is here;
RX_two packs the connect address into a single long, I'm testing it by just grabbing the status page on my router (no password required), but I've also tried it with other pages. I've gone through many iterations, it looks like things choke up at sock[noparse][[/noparse] 2 ].rxtime(50). It looks like this code never completes - if it is included, the prop will hang. I've added spaces between the brackets so they'll show up on the forums, but there aren't spaces in the code.
I'm sure I'm doing something wrong here - my knowledge of sockets is pretty limited, but I can't figure out what it is. Any suggestions appreciated!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Forums RSS Feed!
Gadget Gangster - Share your Electronic Projects
DAT mac_addr byte $02, $00, $00, $00, $00, $05 ' device mac address, must be unique ip_addr byte 192, 168, 1, 252 ' device's ip address ip_subnet byte 255, 255, 255, 0 ' network subnet ip_gateway byte 192, 168, 1, 1 ' network gateway (router) ip_dns byte 192, 168, 1, 1 ' network dns
I setup 2 sockets to listen on port 88.
\sock[noparse][[/noparse] 0 ].listen(88, @tcp_webrx1, rxlen, @tcp_webtx1, txlen) \sock[noparse][[/noparse] 1 ].listen(88, @tcp_webrx2, rxlen, @tcp_webtx2, txlen)
These guys run in a loop & will display the results of sock[noparse][[/noparse] 3 ]. I can get them to display browser request headers just fine.
The part that I think is broken is here;
PRI senddata | i RX_two := constant((192 << 24) + (168 << 16) + (1 << 8) + 1) \sock[noparse][[/noparse] 2 ].connect(RX_two, 80, @tcp_webrx3, rxlen, @tcp_webtx3, txlen) sock[noparse][[/noparse] 2 ].waitConnectTimeout(500) sock[noparse][[/noparse] 2 ].str(@requeststring) repeat i from 0 to 20 newbuff[noparse][[/noparse] i ] := sock.rxtime(50) \sock[noparse][[/noparse] 2 ].txflush sock[noparse][[/noparse] 2 ].close
RX_two packs the connect address into a single long, I'm testing it by just grabbing the status page on my router (no password required), but I've also tried it with other pages. I've gone through many iterations, it looks like things choke up at sock[noparse][[/noparse] 2 ].rxtime(50). It looks like this code never completes - if it is included, the prop will hang. I've added spaces between the brackets so they'll show up on the forums, but there aren't spaces in the code.
I'm sure I'm doing something wrong here - my knowledge of sockets is pretty limited, but I can't figure out what it is. Any suggestions appreciated!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Forums RSS Feed!
Gadget Gangster - Share your Electronic Projects
Comments
I can't answer your question with any authority, as I've not yet tried IP on the Prop. However I thought that each socket needs to listen on a unique port, but you have sock[noparse][[/noparse] 0 ] and sock[noparse][[/noparse] 1 ] both listening on port 88 - might that be confusing things? (Sorry if this is a "red herring").
Cheers,
Simon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.com
Announcement: To cut costs in the current economic climate, we have switched-off the light at the end of the tunnel.
I thought that, too - but it doesn't. In Harrison's demo, he has 3 sockets each listening to port 80, and it works fine.
I've tried it just running 2 sockets, one on port 88, another on port 80. I've also tried it with one socket on port 80 set to listen, and a second socket on port 80 set to send. Still no dice. I also tried reverting to an earlier version of PropTCP (the one used in Harrison's Telnet project), and it didn't work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Forums RSS Feed!
Gadget Gangster - Share your Electronic Projects