I have encountered this same question in numerous forms over the past year, and have not been able to find the solution I am after. As the question has yet again reared its head, I am asking here with renewed vigor that what I am after is indeed possible.
In summary – how does one practically interface with a UNIX port ?
To illustrate the answer I am looking for, I will describe my thought framework:
Historically, if I am writing software in some language, I may occassionaly need to interface with another language, or store some variable on my system for later use, once the programme terminates.
I have found a convenient way of achieving this to write to a file. I find this straightforward in all languages I work with – whether using fprintf
in C or the append character >>
in bash. It also has many other bonuses – such as being editable via a CLI directly, following UNIX permission settings for regular files, etc, etc.
When communicating over a network, there must be a stream of some sort accepting input and returning output. My question is – how do I interface with this stream via a file or files ?
I have limited experience with UNIX sockets, which have presence as system files. I have limited experience using hardware serial ports on my PC – these write their output to a system file.
So – how do I practically read and write from a port on my system ? For example, practically, how would I achieve this in bash or C ?