Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Networking in Basic

18 views
Skip to first unread message

ne...@iank.org.uk

unread,
Apr 21, 2012, 5:33:04 PM4/21/12
to
Hello All
I am trying to add to an existing Basic programme the ability to read data
from a port across a network. In the past I would of used Justin
Fletcher's EasySockets module but this is not 32bit. If anyone can point
me in the direction of an equivalent or a suitable Basic library I would
be eternally grateful. It only has to read a few bytes of data and speed
is not really an issue.

Regards
Ian K

Sprow

unread,
Apr 21, 2012, 6:11:26 PM4/21/12
to
On Apr 21, 10:33 pm, <n...@iank.org.uk> wrote:
> I am trying to add to an existing Basic programme the
> ability to read data from a port across a network.

[snip]

> It only has to read a few bytes of data and speed
> is not really an issue.

Though you don't want the hardware bit, if you go to
http://www.sprow.co.uk/bbc/masternet.htm
and scroll down to the downloads you'll find a simple web server (for
TCP) and NTP client (for UDP) written in BASIC.

Within the program there are functions to manipulate sockets - you can
safely ignore the BBC Micro equivalents!
Sprow.

Alan Adams

unread,
Apr 22, 2012, 7:40:46 AM4/22/12
to
In message <528414d...@iank.org.uk>
I'm ssuming the existing program is a Wimp program. If not, I'm not
sure you can do it.

It will make a big difference in your code whether you can block
waiting for the message, or whether you need the computer to respond
to user input while waiting for data. The latter is a bit more
complicated to code. Assuming the latter...

First you need to know whether the data is being sent using TCP or UDP
packets. There's a fundamental difference between the way these two
work.

UDP (unreliable datagram protocol) doesn't guarantee to deliver the
data, but if is is delivered then the message arrives in a single
piece.

TCP does guarantee to deliver the data (which is why it is the more
common form of transport) but the data may be fragmented, arriving in
several pieces.

For TCP generally you will want a handler called from wimp_pollidle
which checks whether there is anything received. If there is, copy it
into a buffer (NOT a BASIC string, because it may be too long), adding
to what may already be in the buffer and set a flag for the main
program to know something has arrived.

For TCP you will need a way to know whether the buffer contains a
complete message, and where the start and end are. If you have control
over the sender, it's a case of wrapping the message in markers, for
example a character or string that the message itself is guaranteed
never to contain. If not, you need to know exactly what is being sent,
so you can search the buffer for it.

Once your complete message is in the buffer, you can process it. That
initial processing will also need to be in a Wimp_Pollidle call, as
the programme will have to wait for data.

I would strongly advise getting and using !Reporter, if you don't
already. Debugging this stuff can be tricky.

--
Alan Adams, from Northamptonshire
al...@adamshome.org.uk
http://www.nckc.org.uk/

ro...@riscos.org

unread,
May 5, 2012, 5:33:32 AM5/5/12
to
Thanks for your replies. That's got me pointed in the right direction.

Regards
Ian K

0 new messages