Author Topic: TI netcat  (Read 11136 times)

0 Members and 1 Guest are viewing this topic.

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
TI netcat
« on: August 16, 2012, 03:35:46 pm »
(Cross-posted from cemetech for those who haven't seen it there)

I'm working on a project called "tinc", short for "TI netcat". My original plan was to write a program that can talk to a calculator and can either connect or listen for connections over the network. The current incarnation doesn't speak over the network but rather only over stdin/stdout, but it can still speak over the network with the help of nc (or perhaps even inetd). If I decide not to add networking functionality to tinc, I'll probably rename the project to "ticat".

I've been working with Lionel Debroux and Benjamin Moody to make it work with ticables reliably. Now it's at a point where it should be pretty stable (but it's still not ready for a real release yet). I've only tested it with TiEmu and Punix (not that the OS should make a difference).

Get tinc here: https://github.com/abbrev/tinc

Anyway, here's a little networked tinc demo (using nc for the network part):
Code: [Select]
$ mkfifo pipe
$ <pipe nc -l 8002 | ./tinc -c tiemu >pipe
In Punix on the calculator (TiEmu) I ran the "uterm" program, which  is a terminal program that talks over the link port (kind of like minicom in *nix or Hyperterminal in Windows). Then I browsed to http://localhost:8002/ in Firefox.

In the following screenshot, the first 9 lines (11 lines with line wrapping) starting at "GET / HTTP/1.1" are the HTTP request from Firefox. The next 6 lines (starting at "HTTP/1.1 200") are the HTTP reply that I manually typed on the calculator. Firefox displayed the text "Hello world!" in plain text as soon as I hit enter on the last line. Hooray for an impractical web server. :)




Another use for tinc is to use the Punix shell from a real terminal. This works only if Punix is listening for logins over the link port, which is not the case with the demo above (the link port can be opened only once at a time in Punix).

Anyway, here's a short run using the Punix shell in my Linux terminal:
Code: [Select]
$ ./tinc -c tiemu

server login: root
password:
stupid shell v0.2
root@server:~# help
available applets:
 tests     top       cat       echo      true      false     clear     uname
 env       id        pause     batt      date      adjtime   malloc    pid
 pgrp      poweroff  times     sysctltest ps        bt        crash     mul
 div       kill      time      exit      status    help
root@server:~# echo hello world!
hello world!
root@server:~# exit

server login:
This was actually my first use of tinc, but I think the HTTP demo is more impressive. :)

I hope I can get tinc ready for release before too long, and I hope we all can find useful and innovative uses for tinc. I already thought about writing a VNC server for Punix as a sort of replacement for the TI screenshot functionality. Who knows what else we can come up with?
Christopher Williams

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: TI netcat
« Reply #1 on: August 16, 2012, 05:50:04 pm »
Nice, awesome job!!
What about an irc client ? The protocol isnt that complex :D

Offline AzNg0d1030

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 522
  • Rating: +45/-4
  • Hardcore anime watcher.
    • View Profile
Re: TI netcat
« Reply #2 on: August 16, 2012, 09:30:06 pm »
Nice, awesome job!!
What about an irc client ? The protocol isnt that complex :D
I thought someone already made one for Nspire ???
You just lost the game.



Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: TI netcat
« Reply #3 on: August 16, 2012, 10:36:05 pm »
TI-netcat... so now we can plug a cat to our calculator to have Internet?? O.O

Just kidding I read the first post in overall. Sounds really great. I wonder if eventually there could be something like CALCnet but for 68K calcs?

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
Re: TI netcat
« Reply #4 on: August 16, 2012, 11:42:32 pm »
Nice, awesome job!!
What about an irc client ? The protocol isnt that complex :D
Thanks! I'd like to make one, but I have enough projects as it is, and my time is really limited right now. Maybe you could write a simple one in C that reads and writes to a pipe/socket/whatever and to stdin/stdout, and then I can port it to Punix. Note that the select() system call doesn't work yet, so you'll have to find another way to read from the socket/pipe and from stdin without blocking.

I thought someone already made one for Nspire ???
Someone probably did, but I'm working with a TI-92+. My primary OS on it is Punix, which makes it relatively easy to read and write to the link port. But tinc works with any calculator that uses the same low-level data protocol, which includes all of the TI-8x, TI-9x, and I'm sure the Nspire as well. What you do with the data that you read and write... well, that's up to you. :)

TI-netcat... so now we can plug a cat to our calculator to have Internet?? O.O

Just kidding I read the first post in overall. Sounds really great. I wonder if eventually there could be something like CALCnet but for 68K calcs?
I have some plans for making a similar protocol to CALCnet (called Chrisnet for now), but mine will be designed more for TCP/IP networking. globalCALCnet works by sending CALCnet frames over TCP using proxy server(s). With Chrisnet, it's the other way around: IP datagrams will be carried inside Chrisnet frames, much like IP is carried inside Ethernet frames. In fact, it will be similar to Ethernet in some ways. I also have ideas for building a hub to translate Chrisnet frames to Ethernet or SLIP or PPP frames, depending on the cost and complexity of parts needed to build one, so you can plug in your calculator and connect to the Internet over TCP/IP. I'm leaning toward SLIP or PPP since they are simpler and less expensive than Ethernet (which uses... CAT 5 cables! :P). But I haven't even made a proof-of-concept for my protocol, so I'm really putting the cart before the horse until I can demonstrate that my protocol works.

(And I actually haven't worked on hardly anything calculator-related for the last few months, up until about a week ago. My job and family keep me plenty busy.)
Christopher Williams

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: TI netcat
« Reply #5 on: August 17, 2012, 05:50:05 am »
Thanks! I'd like to make one, but I have enough projects as it is, and my time is really limited right now. Maybe you could write a simple one in C that reads and writes to a pipe/socket/whatever and to stdin/stdout, and then I can port it to Punix. Note that the select() system call doesn't work yet, so you'll have to find another way to read from the socket/pipe and from stdin without blocking.

I could do it, but I don't have much experience with sockets/pipes/etc (in C), so I'll need to see.
What standard libs can I use in punix ?
« Last Edit: August 17, 2012, 02:50:58 pm by Jim Bauwens »

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
Re: TI netcat
« Reply #6 on: August 17, 2012, 03:07:06 pm »
Thanks! I'd like to make one, but I have enough projects as it is, and my time is really limited right now. Maybe you could write a simple one in C that reads and writes to a pipe/socket/whatever and to stdin/stdout, and then I can port it to Punix. Note that the select() system call doesn't work yet, so you'll have to find another way to read from the socket/pipe and from stdin without blocking.

I could do it, but I don't have much experience with sockets/pipes/etc, so I'll need to see.
What standard libs can I use in punix ?

Only the C standard library and POSIX system interfaces. Even those are incomplete (such as the select() system call).

Here is an incomplete list of functions that work which I think you would need to write a simple IRC client:
  • open/close/read/write
  • printf/sprintf/fprintf
  • putc/putchar
  • getc/getchar
  • tolower/toupper/isalpha/isdigit/etc (all of ctype.h)
  • malloc/realloc/calloc/free
  • setitimer/getitimer
  • atoi/strtol
  • all str* and mem* (string.h) functions
  • signal/sigaction

The lack of select() is slightly annoying, but you can get around that by setting an interval timer (with setitimer()) to run every 100ms or so to interrupt read() calls on the link port and the terminal. This is what I did in the uterm program. That reminds me: I need to implement the O_NONBLOCK flag for file descriptors which would make read() and write() non-blocking. That shouldn't be too difficult, at least compared to select().
Christopher Williams

Offline DWLooney

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 14
  • Rating: +0/-0
    • View Profile
Re: TI netcat
« Reply #7 on: August 18, 2012, 12:30:10 pm »
Wow, Iv'e always wanted to have internet on the nspire.

Do you think that the periphal used to connect the nspire to their special router could work? That would be awesome XD

This looks like a great project!

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: TI netcat
« Reply #8 on: August 21, 2012, 05:30:42 am »
Doh, I've missed the topics on both Cemetech and Omnimaga. Now subscribed.

Quote
But tinc works with any calculator that uses the same low-level data protocol, which includes all of the TI-8x, TI-9x, and I'm sure the Nspire as well.
Nope, the Nspire doesn't have a proprietary 2.5mm stereo jack female plug ;)
The 84+ keyboard suitable for Clickpad/Touchpad models has one, but unless one is hot-switching the keyboards during a Ndless program that disables interrupts, the Nspire turns off when the standard keyboard is removed, and starts 84+ emulation mode when turned back on with the 84+ keyboard.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
Re: TI netcat
« Reply #9 on: August 21, 2012, 04:16:49 pm »
Quote
But tinc works with any calculator that uses the same low-level data protocol, which includes all of the TI-8x, TI-9x, and I'm sure the Nspire as well.
Nope, the Nspire doesn't have a proprietary 2.5mm stereo jack female plug ;)
The 84+ keyboard suitable for Clickpad/Touchpad models has one, but unless one is hot-switching the keyboards during a Ndless program that disables interrupts, the Nspire turns off when the standard keyboard is removed, and starts 84+ emulation mode when turned back on with the 84+ keyboard.
Ah, you are correct. What I should have said is "tinc works with any calculator that is supported by ticables", which also covers Direct USB on the models that support it.
Christopher Williams

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
Re: TI netcat
« Reply #10 on: August 23, 2012, 09:43:47 pm »
Why was this moved to TI-68K Projects? It's a computer program that works with nearly all calculator models (I just happen to use it with Punix in my demos).

Can we get a new sub-forum for calculator-related computer programs?
Christopher Williams

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: TI netcat
« Reply #11 on: August 24, 2012, 05:12:06 pm »
Sorry, I took a look at the screenshot and assumed it was for the 68K series :P

EDIT: Now that I read the topic ... that is really awesome. One terribly impractical idea I've had for a while is to make a web server use TI-BASIC for a scripting language. Your little demo did it with an actual calculator ;D
« Last Edit: August 24, 2012, 05:16:26 pm by Deep Thought »




Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: TI netcat
« Reply #12 on: August 26, 2012, 03:29:55 am »
This is pretty amazing! I would be one very serious user** if you added TCP networking support! :D
The Nspire (and friends) would appreciate some Internet connectivity. ;)

(For the Nspire, USB communication needs to be implemented Ndless side beforehand)

** By user, I don't mean just accessing the Internet, I also mean using it as a component for a major project! ;)
« Last Edit: August 26, 2012, 03:30:20 am by alberthrocks »
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: TI netcat
« Reply #13 on: August 26, 2012, 03:51:55 am »
FWIW, there's already some TCP/IPv4 code for the TI-68k series, by Samir Ribic: http://www.ticalc.org/archives/news/articles/4/43/43965.html . I've just checked that it uses the OS routines (e.g. OSLinkReset and "transmit", which is an old name for an official routine), it doesn't do low-level linking by itself with a special protocol.

Being made in 2000, it's a pretty old-style TI-68k/AMS C program, though, and the accompanying instructions are similarly old.
Modern GCC4TI (with support for regparm and other stuff), and some code changes (a number of tricks I wrote in S1P9 apply, such as constifying char* arrays on the stack, or inlining trivial functions), would decrease the size. Old-style (K&R) function prototypes are not a problem wrt. optimization, but they're ugly by modern standards ^^
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline christop

  • LV3 Member (Next: 100)
  • ***
  • Posts: 87
  • Rating: +20/-0
    • View Profile
Re: TI netcat
« Reply #14 on: August 29, 2012, 10:56:06 pm »
Let me clear up some possible misconceptions.

First, if I add networking to tinc, it won't do anything that the regular nc (netcat) doesn't already do. It'll be able to talk with only one other computer at a time, and you'll have to pick the IP or host name of the other computer when you run it (or put it in listen mode, then one other computer can connect and talk to the calculator). The calculator can't select the IP to connect to, and it can't know what IP connects to it.

Second, the calculator link protocol has no way to detect or signal an end-of-file condition or, by extension, to either close a network connection or detect when one has closed. In the HTTP demo I had to explicitly put the "Content-length" and "Connection: close" header in the response which told the browser when to close the connection. The calculator didn't know that tinc had exited when the browser closed the connection.

Third (and this is not just a tinc issue), the TI link protocol is only half-duplex, which means only one side can send a byte at a time. Normally this isn't a problem--the two sides can take turns talking at a fast enough rate that it isn't noticeable--but if both sides try to talk at the same time, there is a problem. It's a double problem because the protocol sometimes makes it difficult or impossible to distinguish between a "collision" and the other side simply not responding, so it's usually not possible to recover from it, leading to lost data. This happens a lot during interactive sessions, such as using the calculator as a terminal or a terminal server (I've done both with Punix :)). For example, if the computer is sending a lot of data (perhaps I cat a large file) and I try to type anything while it's sending data (say, Ctrl-C to kill cat), the outgoing data is likely to collide with the incoming data. There's nothing I can do with tinc to fix this problem, either. It's too bad TI didn't use a standard serial UART in their calculators as Casio did in theirs. (I am investigating adding a full-duplex "rs232" driver to Punix which will simulate a UART, but it will run at 2400bps at the very fastest.)

What Lionel mentioned (TCP/IP on the calculator) would fix the first two issues, but it's kind of heavy-weight for a calculator (but I would like to implement it in Punix anyway :)).

What tinc with networking (or used with nc) will let you do is simple point-to-point communication with another calculator anywhere across the globe, as long as you have network connectivity between them. Imagine playing a multi-player game with someone in another country! The game won't even have to use any special protocols like Kerm's CALCnet/globalCALCnet (which I admit are pretty neat protocols). The latency might kill in some types of programs (action games), but I'm sure it'll still be fun. :D

Lionel: I've seen Samir's TCP/IP demo before, and I've also looked at TinyTCP (which his demo is based on) and other small TCP/IP stacks. My favorite at the moment is lwIP. It has a nice callback-driven API which looks like it might fit in well with the Punix kernel (the kernel would be lwIP's "application", and Punix already has timers, a memory allocator, and other necessities for lwIP to use).
Christopher Williams