Network Messaging in Basic
Graham (1584) 30 posts |
Hi All, I am looking for some help, I need a way to send messages from one PI to another via the network and using Basic code. The idea is to relay real time data from one to another a bit like wimp messages. Can anybody point me to a module that can do this or a quick bit of basic code that I can adapt, I was thinking Sockets but I am struggling to understand the jargon. Thanks |
John Williams (567) 768 posts |
Won’t ShareFS allow you to examine files on the source m/c from the second m/c in practically real time? |
Graham (1584) 30 posts |
I did think of that way but I have 7 PI’s setup and keeping track of file data was looking awkward so I was thinking if I could just broadcast a message with a sender id and data string that would be easy to track. |
Steve Pampling (1551) 8170 posts |
Sounds like the unfinished Jaffasoft ActiveApps would be ideal. Edit: I recall looking at this back when the Pi appeared and people started doing things to cluster them etc. |
John Williams (567) 768 posts |
I did a text messaging system years ago where the receiver just used ShareFS to check for the presence of the message as a file at short intervals. This was between two RISC OS machines, but tracking multiple machines could easily be arranged to depend on which file each machine checked for. But there may well be better ways of doing it. |
nemo (145) 2547 posts |
There are two problems to solve – one is node discovery (ie what are the addresses of your various PIs) and the other is protocol (ie what do they say to each other and how). There are various technologies for node discovery, but the native one is Freeway – define a new Freeway object type as part of your program and all the nodes will find each other over the network. This is how ShareFS and shared printers work.
However, that just gives you the addresses of the various nodes (and their host names, if that’s important). To communicate you’ll need to open sockets for a chosen port on your various nodes and send messages to that port, at those addresses, |
Steve Pampling (1551) 8170 posts |
Which is rather the point of the Jaffasoft (not finished) offering I think.
That’s the more sociable alternative to stand-alone then? |
nemo (145) 2547 posts |
Oops. Spotted the typo before I saw your reply Steve. Freeway is rather underrated IMO. It (especially in remote mode) punches through networks where Windows and Bonjour fail to connect. ShareFS is a network vulnerability, but the fact that it works so trivially easily is down to Freeway. I’ve had emulated RISC OS machines connect instantly across multiple networks where the host PCs could not and would not connect by any mechanism invented by MS… and they didn’t just fail, they failed sloooooooowlyyyyyyyyy. |
Graham (1584) 30 posts |
Thanks for the ideas, so it looks like Sockets/Freeway are still the best way, I will have to read up more and try and work it out. |
Steve Pampling (1551) 8170 posts |
I thought SSDP in Windows was a bit naff, until I saw Bonjour in action. 1 While “chatty” and non-routable it was at least pretty light. |
Dave Higton (1515) 3526 posts |
Just checking – you only need to send messages one to one, not one to many, yes? I did have a UDP messaging pair of apps on my web site years ago, but I withdrew them pending some updates, only to find that sometimes the address resolution would come up with a byte-reversed address but I couldn’t for the life of me see where I had got two code paths that behaved differently. The apps are written in BASIC, so could form a good basis for what you need to do. |
nemo (145) 2547 posts |
The biggest problem with the Socket_ SWIs is the documentation (hardly news to RISC OS users I know). However, there’s not much to creating a non-blocking socket to listen for broadcast datagrams (four SWIs, plus one to close it at the end), and sending broadcast datagrams is a single SWI operation. The hard part is knowing all the magic runes. The terse version is:
And when quitting
Then in your null poll
And finally, to broadcast the message
Feel free to allocate yourself a port that hasn’t been used and preferably >60,000 If you need to have handshake communications, you will either have to embed the sender’s IP and port in the message (to which a direct reply can be sent) or use the Socket_Recvfrom SWI. |
John Sandgrounder (1650) 574 posts |
My solution to this problem, many years ago, was to use wget on the sending computer and a webserver script on the receiving computer. As wget has been widely ported to mamy operating systems and webservers are also widely available, this works between almost ony two computers of any type and across the Internet as well. From BASIC on RISCOS call wget via an obey file otherwise the call of wget does not return. On RISCOS, simple CGI webserver scripts can be written in Basic if using WebJames as the webserver. |
Steve Pampling (1551) 8170 posts |
There are various lookup resources but the wikipedia isn’t particularly complete/accurate The one on this link does better.
If there’s one thing I hate with a passion it’s IP reliance embedded in the code, it’s almost like no one ever invented name resolution. What’s that new fangled DNS stuff about anyway? |
nemo (145) 2547 posts |
Yeah, to be clear I was advocating using Freeway to discover the host to send an initial message to, but communications between nodes should thereafter be replies to addresses sent in the packets – “in the message” I wrote, not ‘in the code’. |
Steve Pampling (1551) 8170 posts |
Phew. Relax with a beer time. |