Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use files as a bidirectional communication channel between two remote processes (sort of "sockets over files")?

Here is the scenario:

  • An user have access to two machines

  • These machines can't communicate with network sockets because of firewall restrictions

  • But, both have access to a common network share with read/write permissions on a third machine

My question is: is it possible to write a small application executed on both machines that allows to establishes a communication channel between the two by using only files on the network share? Ideally it would emulates streams and sockets behaviour.

I imagine that:

1) it would involve to have two files used for communication, one for each direction

2) and having the possibility to read a file while another process is writing it... over the network.

But I'm not sure if it is feasible, mainly because I doubt about the point 2). Maybe it is possible in Unix-like environements with NFS, though.

Is it possible? Is it already existing?

like image 525
Gabriel Cuvillier Avatar asked Sep 10 '10 17:09

Gabriel Cuvillier


2 Answers

I think it's a good idea to split the stream into packets first. Then these packets should appear as files in the common directory. There must be two "namespaces" for the two ways (a->b and b->a). For the easy debugging, file names should contain a timestamp, not just an incremental part.

There's only one issue with files: even if the file is pretty small, the receiver can catch it when it's not fully flushed, I mean the file is only halfway ready (common case: 0 byte long), or a network error occurred during the transfer. Avoid this situation, the sender should:

  • create the file on a temporary name,
  • write the content, close it,
  • then rename it to the final name (with timestamp etc.).

So, the receiver will only pick the file after the rename, when it's 100% sure, that the it's fully written.

Before sending a new file, the sender may check for the temporary file, if it exists, it means that the last transmit was aborted.

When creating a new transmit file, the sender should create an info file, which contains information about the transmit packet being sent, so upon an abortion, it will contain information about the failed packet. Maybe, the only information is the time of the transmit (remember: the temporary file name does not contain timestamp), but it's better than nothing.

like image 153
ern0 Avatar answered Jan 03 '23 01:01

ern0


How about this:
When machine A wants to send a message to machine B, it creates a file called _toBfromA_12782 (where 12782 is the current timestamp). It writes the content to the file and then changes the name to remove the first underscore.
Every few seconds, every machine checks if there are files with a file name which starts with toX where X is their own name. If multiple messages are found, they can then be ordered according to the time stamps. After reading the message file, the recipient deletes the file.
This assumes that all participants have a synchronized time but if they don't this too can be worked out (or really ignored actually).

like image 23
shoosh Avatar answered Jan 03 '23 01:01

shoosh