Discussion:
HTML terminal
(too old to reply)
muta...@gmail.com
2021-10-16 08:29:32 UTC
Permalink
I moved a step closer to an HTML terminal with the below
code. Someone else provided the Javascript so I don't know
how to get rid of the utf8 stuff yet.

One thing that surprised me was that unlike an nntp or telnet
session, http seems to send an HTML page and then it never
gets a response back, ie the read() just sits there. It seems that
the browser is designed to ignore that open connection (neither
end seems to close it) and then it starts a brand new connection.
This means I didn't get the expected "GET /?key=X'.

My desire is for PDOS/386 to effectively open a serial port
connection to a BBS that is emitting HTML code instead of
ANSI escape sequences. As such, I need the "GET /" to go
up via the same line. There's not really a concept of a new
connection.

But because I would like the BBS to be able to operate with
a normal web browser too, I think the BBS needs to be
defined to have either persistent http connections or
non-persistent. ie both forms are valid.

Unless there's a way to get the browser to keep the
connection open?

Note that my htmlterm application running under PDOS/386
won't bother actually interpreting that javascript, it will just
assume that the javascript is soliciting a keystroke and send
a "GET /?key=whatever" up the serial line.

BFN. Paul.



<html>
<body>
line 1<br>
line two<br>
line 3<br>
<script>
async function handle_key_press(e) {
const utf8 = new TextDecoder('utf-8');
const resp = await window.fetch('/?key=' + e.key);
const reader = resp.body.getReader();
const body = document.querySelector('body');

body.innerHTML = '';

while (true) {
const {value, done} = await reader.read();
if (done) break;
body.innerHTML += utf8.decode(value, {stream: true});
}
}
window.onkeypress = handle_key_press;
</script>
</body>
</html>
JJ
2021-10-17 07:39:42 UTC
Permalink
Post by ***@gmail.com
I moved a step closer to an HTML terminal with the below
code. Someone else provided the Javascript so I don't know
how to get rid of the utf8 stuff yet.
One thing that surprised me was that unlike an nntp or telnet
session, http seems to send an HTML page and then it never
gets a response back, ie the read() just sits there. It seems that
the browser is designed to ignore that open connection (neither
end seems to close it) and then it starts a brand new connection.
This means I didn't get the expected "GET /?key=X'.
My desire is for PDOS/386 to effectively open a serial port
connection to a BBS that is emitting HTML code instead of
ANSI escape sequences. As such, I need the "GET /" to go
up via the same line. There's not really a concept of a new
connection.
But because I would like the BBS to be able to operate with
a normal web browser too, I think the BBS needs to be
defined to have either persistent http connections or
non-persistent. ie both forms are valid.
Unless there's a way to get the browser to keep the
connection open?
Note that my htmlterm application running under PDOS/386
won't bother actually interpreting that javascript, it will just
assume that the javascript is soliciting a keystroke and send
a "GET /?key=whatever" up the serial line.
BFN. Paul.
Use the appropriate HTTP request header to keep the connection open.
However, the HTTP server must also support the header.

Though IMO, it's better to use WebSocket for this kind of purpose.
muta...@gmail.com
2021-10-17 22:03:37 UTC
Permalink
Post by JJ
Post by ***@gmail.com
I moved a step closer to an HTML terminal with the below
code. Someone else provided the Javascript so I don't know
how to get rid of the utf8 stuff yet.
One thing that surprised me was that unlike an nntp or telnet
session, http seems to send an HTML page and then it never
gets a response back, ie the read() just sits there. It seems that
the browser is designed to ignore that open connection (neither
end seems to close it) and then it starts a brand new connection.
This means I didn't get the expected "GET /?key=X'.
My desire is for PDOS/386 to effectively open a serial port
connection to a BBS that is emitting HTML code instead of
ANSI escape sequences. As such, I need the "GET /" to go
up via the same line. There's not really a concept of a new
connection.
But because I would like the BBS to be able to operate with
a normal web browser too, I think the BBS needs to be
defined to have either persistent http connections or
non-persistent. ie both forms are valid.
Unless there's a way to get the browser to keep the
connection open?
Note that my htmlterm application running under PDOS/386
won't bother actually interpreting that javascript, it will just
assume that the javascript is soliciting a keystroke and send
a "GET /?key=whatever" up the serial line.
Use the appropriate HTTP request header to keep the connection open.
However, the HTTP server must also support the header.
I'm confused by this. It seems to be the browser that is
initiating a new request instead of reusing the current
connection. Maybe that's a Javascript limitation?

Regardless, I tried sending this:

#define KEEP_ALIVE "HTTP/1.1 200 OK\r\n" \
"Connection: Keep-Alive\r\n" \
"\r\n"

before the HTML page, but it didn't change the behavior.
Post by JJ
Though IMO, it's better to use WebSocket for this kind of purpose.
Note that the goal is for the server to be very simple, rendering
an HTML page instead of an ANSI terminal. Just a whole lot of
lines with <br> between them. And the terminal will be simple
too, just assuming the javascript is correct, not bothering to
parse it. My understanding is that websockets are a more
complicated thing.

And note that going across the internet, I'm just going to have
the serial ports on both ends using an emulator to talk TCP/IP.
In a business setting there could potentially be a real serial
cable.

BFN. Paul.
JJ
2021-10-18 07:46:29 UTC
Permalink
Post by ***@gmail.com
Post by JJ
Use the appropriate HTTP request header to keep the connection open.
However, the HTTP server must also support the header.
I'm confused by this. It seems to be the browser that is
initiating a new request instead of reusing the current
connection. Maybe that's a Javascript limitation?
#define KEEP_ALIVE "HTTP/1.1 200 OK\r\n" \
"Connection: Keep-Alive\r\n" \
"\r\n"
before the HTML page, but it didn't change the behavior.
Which is why the header must be supported by the server too. Not just the
client. And actually do something as requested, rather than "just talks".
Post by ***@gmail.com
Post by JJ
Though IMO, it's better to use WebSocket for this kind of purpose.
Note that the goal is for the server to be very simple, rendering
an HTML page instead of an ANSI terminal. Just a whole lot of
lines with <br> between them. And the terminal will be simple
too, just assuming the javascript is correct, not bothering to
parse it. My understanding is that websockets are a more
complicated thing.
And note that going across the internet, I'm just going to have
the serial ports on both ends using an emulator to talk TCP/IP.
In a business setting there could potentially be a real serial
cable.
BFN. Paul.
WebSocket guarantees that the network connection is reused. But neither one
matter if the server doesn't do anything to keep the connection alive.
Loading...