[fpc-pascal] Thoughts on Shell Approach to TCP Sockets

Coyo Stormcaller coyo at darkdna.net
Thu Mar 19 00:57:48 CET 2015


Despite documentation and manuals, I have not figured out how to use TCP 
sockets in Object Pascal, since there doesn't seem to be a primitive for 
it, or any easy way to instantiate sockets and manipulate incoming 
connections.

So my approach to sockets is to do it externally. A Bash shell script 
invokes another script, such as Ruby for binding the socket. Upon 
recieving a socket connection, it invokes an Object Pascal command line 
program, passing it socket traffic as standard input.

Another similar approach is to pre-parse serialized socket objects and 
then re-serialize them in a processed form, for the Object Pascal 
program to further process and manipulate from standard input. If I knew 
how to do more of this with pure Object Pascal, I'd do it that way.

But as it is, I'm thinking breaking up the program into components in a 
bunch of different languages. The way it's designed right now, a Bash 
Shell script is invoked by /etc/init.d to manage the program, including 
re-binding to the socket, rehashing, etc. A cron job periodically 
re-calls the program so that time-related functions can be invoked. this 
lets me get away with not using a core while-true loop. all components 
execute as a script and then exit until the next time the main Bash 
Shell script is invoked.

The /etc/init.d script is treated as an initializer, and is used to 
manage it, but really the main Bash Shell script in cron is what does 
the lion's share. A few of the persistent scripts are those that handle 
things like sockets and long-lived connections between components.

At the moment, all objects are stored on file in flat-file format, and 
serialized as an IRC-like text-line object notation, but I want to 
eventually switch to using MsgPack, ProtoBuf and SQLite for 
serialization and object storage, and libpurple for the many protocols 
libpurple supports.

The name of the application in question is named Tanis. Tanis is an 
automated personal assistant, or pseudo-AI. It does various things. At 
the moment, all it is is a protocol-agnostic bot that can retrieve 
weather, greet people with a random quote, and various IRC bot 
functions. It can also control chat management and such.

I'm working on an email management console, and from there a Usenet 
interface. It's going smoothly enough, I suppose. However, I really like 
Object Pascal, and the more I can do with it, and Common Lisp for the 
learning portions, the better.

I'd prefer for the sockets to be handled by Object Pascal, but I do not 
know how to do this. I'm not very good at using other peoples' code and 
libraries in general, so I tend to focus on either well-documented 
standard libraries that are easy to access and use, or using purely my 
own code.

I'm fairly proficient with Bash Shell, and I like Regular Expressions, 
and am fairly conversant with Extended Regular Expressions, so I tend to 
focus on using Bash Shell scripts as much as seems reasonable, while 
invoking other program components from within Bash while the Bash Shell 
script executes. There are three different Bash Shell scripts. One is an 
infinite loop, which can be started and stopped with /etc/init.d commands

Anyway, thank you for your time and patience.



More information about the fpc-pascal mailing list