6
\$\begingroup\$

Task:

Your task is to create two programs in different languages that can communicate one-way to each other. Your sending (tx) program will take input, for either stdin or a query, and send it along to the receiving (rx) program. Your rx program will then print out the data that it receives.

Rules:

  • The two programs must communicate one way from the tx to the rx side, so anything typed in tx will appear in rx.
  • They will be running on the same computer, in different shells/windows.
  • They will be running in separate instances, and you are not allowed to chain them (in bash, prog1 | prog2)
  • The programs must be written in different languages.
  • They can use any data transfer method, but you must be able to transfer ASCII text.
  • This is a , so the most up voted answer wins.
    • Note to voters: look for creativity!
\$\endgroup\$
  • 3
    \$\begingroup\$ Don't give up on this one! I like the idea, but it needs some more specific instructions. \$\endgroup\$ – Jonathan Van Matre Mar 17 '14 at 12:52
  • \$\begingroup\$ @TheDoctor - Perhaps specify what type of data should be sent between or some other restriction to make it more difficult. Another option would be to specify environmental constraints (no HTTP interface) \$\endgroup\$ – David Wilkins Mar 17 '14 at 15:34
5
\$\begingroup\$

Bash and GNU Awk communicating on TCP

Bash transmitter:

cat>/dev/tcp/localhost/8080

GNU Awk receiver:

BEGIN{getline<"/inet/tcp/8080/0/0";print}

Sample run:

Bash in terminal 1:

bash-4.2$ cat>/dev/tcp/localhost/8080
Bash says hello to Awk
^D

GNU Awk in terminal 2:

bash-4.2$ gawk 'BEGIN{getline<"/inet/tcp/8080/0/0";print}'
Bash says hello to Awk

Both bash and gawk provides special filenames (/dev/tcp/host/port in bash since 2.04, /net-type/protocol/local-port/remote-host/remote-port in gawk since 3.1.0) for simple networking. These are extensions not specified in the POSIX shell and Awk language standards.

\$\endgroup\$
  • 2
    \$\begingroup\$ Please mention and underline that you are using gawk features probably not present in most other awk implementations. Thanks! \$\endgroup\$ – yeti Mar 18 '14 at 0:07
8
\$\begingroup\$

Original Lisp Eliza communicating with yes

Original Eliza lisp code "communicating" with with unix yes utility.

First create a FIFO special file:

mkfifo in

Then we make the two programs communicate together (which means that the patient will answer YES to all questions).

clisp coselleliza1969and1972.lisp < in | tee out.txt | yes 'yes.'  > in

Output is inifnite and starts with:

TELL ME YOUR PROBLEMS. PLEASE TERMINATE INPUT WITH A PERIOD OR A QUESTION MARK.
IS THERE SOMETHING BOTHERING YOU?
WHY ARE YOU SO SURE?
I SEE.
I UNDERSTAND.
CAN YOU BE MORE INFORMATIVE?
WHY ARE YOU SO SURE?
I SEE.
I UNDERSTAND.
PERHAPS YOU'D RATHER TALK ABOUT SOMETHING ELSE.

More variety if it communicates with another instance of itself:

clisp coselleliza1969and1972.lisp < in | clisp coselleliza1969and1972.lisp | tee out.txt > in

Output starts with:

TELL ME YOUR PROBLEMS. PLEASE TERMINATE INPUT WITH A PERIOD OR A QUESTION MARK.
WHY ARE YOU CONCERNED OVER MY PROBLEMS?
I AM NOT SURE I UNDERSTAND YOU FULLY.
SUPPOSE * WHY WERE NOT I CONCERNED OVER YOUR PROBLEMS.
IS IT BECAUSE YOU ARE NOT SURE YOU UNDERSTAND I FULLY THAT YOU CAME TO ME?
YOU SAY YOU CONCERNED OVER MY PROBLEMS?
POSSIBLY THAT IS FOR THE BETTER.
SUPPOSE YOU SAY I CONCERNED OVER YOUR PROBLEMS.
POSSIBLY * POSSIBLY THAT REALLY IS NOT FOR THE BETTER.
OH? I SAY YOU CONCERNED OVER MY PROBLEMS?
WHAT IF REALLY WERE FOR THE BETTER?
PLEASE GO ON.
CAN YOU ELABORATE ON THAT?
WHAT DOES THAT SUGGEST TO YOU?
TELL ME MORE ABOUT YOUR PROBLEMS.
WHAT MAKES YOU THINK I ELABORATE ON THAT?
PERHAPS THAT CONCERNS YOUR PROBLEMS.
WHAT ABOUT YOUR OWN PROBLEMS?
WHO ARE YOU REALLY TALKING ABOUT?
YOU DON'T SEEM QUITE CERTAIN.
EARLIER YOU SAID YOU WERE NOT SURE YOU UNDERSTAND I FULLY.
TELL ME MORE ABOUT * WHO.
SUPPOSE YOU DON'T SEEM QUITE CERTAIN.
OH? I SAID I WAS NOT SURE I UNDERSTAND YOU FULLY?
ARE YOU STILL NOT SURE YOU UNDERSTAND I FULLY?
WHAT MAKES YOU THINK I DON'T SEEM QUITE CERTAIN?
WOULD YOU LIKE TO DISCUSS YOUR PROBLEMS?
DO YOU SAY YOU SAID YOU WAS NOT SURE YOU UNDERSTAND I FULLY FOR SOME SPECIAL REASON?
DID YOU THINK * MIGHT NOT BE I STILL NOT SURE I UNDERSTAND YOU FULLY?
WHO ARE YOU REALLY TALKING ABOUT?
SUPPOSE YOU LIKE TO DISCUSS MY PROBLEMS.
OH? I SAY I SAID I WAS NOT SURE I UNDERSTAND YOU FULLY FOR SOME SPECIAL REASON?
WHAT MAKES YOU THINK I THINK * MIGHT NOT BE YOU STILL NOT SURE YOU UNDERSTAND I FULLY?
* WHO PERHAPS ARE I REALLY TALKING ABOUT.
WHO ARE YOU REALLY TALKING ABOUT?
WHAT ELSE WOULD YOU LIKE TO DISCUSS?
TELL ME MORE ABOUT YOURSELF?
SUPPOSE YOU THINK YOU THINK * MIGHT NOT BE I STILL NOT SURE I UNDERSTAND YOU FULLY.
WHY THE UNCERTAIN TONE?
SUPPOSE * WHO WERE NOT I REALLY TALKING ABOUT.
OH? I LIKE TO DISCUSS?
WHY DO YOU SAY THAT JUST NOW?
WHAT MAKES YOU THINK I THINK I THINK * MIGHT NOT BE YOU STILL NOT SURE YOU UNDERSTAND I FULLY?
I AM NOT SURE I UNDERSTAND YOU FULLY.
OH? YOU REALLY TALKING ABOUT?
PLEASE GO ON.
WHAT ELSE DO YOU LIKE?
WHO ARE YOU REALLY TALKING ABOUT?
SUPPOSE YOU THINK YOU THINK YOU THINK * MIGHT NOT BE I STILL NOT SURE I UNDERSTAND YOU FULLY.
HOW LONG HAVE YOU BEEN NOT SURE YOU UNDERSTAND I FULLY?
DID YOU TELL ME YOU WERE NOT SURE YOU UNDERSTAND I FULLY?
OH? I REALLY TALKING ABOUT?
MAYBE NOW WE CAN DISCUSS WHY YOU ARE NOT SURE YOU UNDERSTAND I FULLY.
WHAT MAKES YOU THINK I LIKE?
POSSIBLY * WHO REALLY ARE NOT I REALLY TALKING ABOUT.
WHO ARE YOU REALLY TALKING ABOUT?
SUPPOSE YOU BEEN NOT SURE I UNDERSTAND YOU FULLY.
OH? I TELL YOU I WAS NOT SURE I UNDERSTAND YOU FULLY?
WOULD YOU LIKE TO DISCUSS YOUR PROBLEMS?
THAT'S QUITE INTERESTING.
\$\endgroup\$
  • \$\begingroup\$ Not exactly what I was asking for \$\endgroup\$ – TheDoctor Mar 17 '14 at 13:11
  • 4
    \$\begingroup\$ Our custom is to tag submissions that are not your own work as community wiki. That being said, even though it's not really a true answer to the specs, this is hilarious and awesome! Now I'm curious to see what happens if you get Racter and Eliza talking to one another. \$\endgroup\$ – Jonathan Van Matre Mar 17 '14 at 15:03
  • \$\begingroup\$ A (very short) dialogue between Racter and Eliza can be found here: stanford.edu/group/SHR/4-2/text/dialogues.html (you need to scroll down quite a bit). \$\endgroup\$ – celtschk Mar 23 '14 at 2:30
4
\$\begingroup\$

PHP + Bash

Bash - rx.sh

#!/bin/bash
tail -f output

PHP - tx.php

<?php
$fd=fopen("output", "w");
$msg = print_r($_GET, true);
fputs($fd, $msg);
fclose($fd);
?>

Query the program with rx.php?<message> or alternately, using a third language,

query.html

<body>
Enter the message to send:
<form action="tx.php" method="get">
<input type="text" name="message">
<input type="submit" value="Submit">
</form>
</body>
\$\endgroup\$
4
\$\begingroup\$

Perl and Rebol via ps (process status)

tx.pl

use strict;
use warnings;

my $line;

while (chomp(my $msg = <>)) {
    $line++;
    $0 = "!!$line!!$msg";
    last if $msg eq 'q';
}

rx.reb

Rebol []

get-ps-msg: has [ps msg] [
    ps: copy ""
    call/output "ps" ps
    parse ps [thru "!!" copy msg to #"^/"]
    msg
]

print-msg: func [m /no-warning] [
    unless no-warning [print-warning? m]
    print next next find last m "!!"
]

print-warning?: func [m /local prev new] [
    prev: first back back tail m
    new:  last m
    prev: to-integer copy/part prev find prev "!!"
    new:  to-integer copy/part new  find new  "!!"
    if new != (prev + 1) [print ["WARNING: Out of sequence, expected" prev + 1 "but got" new]]
]

messages: []                     ; state: records all messages
until [not none? m: get-ps-msg]  ; lets wait until first msg appears
print-msg/no-warning append messages m

; loop until messages disappear from ps
until [
    if m != last messages [print-msg append messages m]
    none? m: get-ps-msg
]

So whats going on here? Well if you start tx.pl and then look at ps in another session you will see something like this:

$ ps
  PID TTY           TIME CMD
32171 ttys001    0:00.02 -bash
32432 ttys001    0:00.01 perl tx.pl

Perl allows you to amend what appears in the CMD (Command) column of ps by amending the $0 variable. So for e.g. if tx.pl was this:

$0 = "hello mum!";
sleep 10;

Then you'll see this in ps while the script is still running:

$ ps
  PID TTY           TIME CMD
32171 ttys001    0:00.02 -bash
32433 ttys001    0:00.01 hello mum!

So we can use this to send messages from one script to another. The Rebol receiving script simply monitors ps for all messages sent to ps from the Perl script.

NB. The Rebol script does contain some extra bits that aren't really necessary (see warnings & recording all messages).

Usage: Do perl tx.pl and rebol -qws rx.reb in separate sessions and everything you type into transmitting session will appear in the receiving session. Once the transmitting session is closed (enter 'q' or ^C) then the receiving script automatically quits.

Tested on Mac OSX 10.7. Requires Rebol 2 at this moment because call/output not currently implemented in Rebol 3.

\$\endgroup\$
3
\$\begingroup\$

sh tx with awk rx connected by a fifo

tx in sh... make a fifo, read user input and send it to fifo, remove fifo.

Run this in one terminal, enter a line and start the receiver in a different terminal.

(yeti@aurora:4)~$ mkfifo F ; read X ; echo $X > F ; rm F
xyzzy

rx in awk ... read fifo, print line and terminate.

(yeti@aurora:5)~$ awk '1' F
xyzzy

A direct connection of tx and rx by a pipe would be shorter but far less interesting.

The fifo would allow tx and rx to be run by different UIDs if the fifo's permissions are set to alow read by others.

\$\endgroup\$
2
\$\begingroup\$

Shell script and not-quite-HTML

Sending code:

#!/bin/sh
cat >> ~/receiver.html

Receiving code - must be located at ~/receiver.html:

<meta http-equiv="Refresh" content="1">
\$\endgroup\$
  • \$\begingroup\$ Inspired choice of rx language! \$\endgroup\$ – tomsmeding Mar 18 '14 at 6:59
2
\$\begingroup\$

q and k

Receiver, rx.q, in q

\p 29010

Transmitter, tx.k, in k

.z.pi:{`::29010(-1;x)};
\$\endgroup\$
1
\$\begingroup\$

C++

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    char input[100];
    cin>>input;
    ofstream inputfile("temp.txt");
    inputfile<<input;
    inputfile.close();
    return 0;
}  

C++11

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    char output[100];
    ifstream outputfile("temp.txt");
    outputfile>>output;
    inputfile.close();
    cout<<output;
    return 0;
}  

They communicate through a text file. In C++ code the input is written in a text file and is then collected by C++11 code.

But, C++ is a subset of C++11
If the asker feels cheated please comment I'll delete this answer! sorry :P

\$\endgroup\$
  • \$\begingroup\$ I see different versions of the same language, especially if they don't differ that much as the same language. Should be a standard loophole. Nicely found anyway :) \$\endgroup\$ – tomsmeding Mar 18 '14 at 6:59
  • \$\begingroup\$ Since C++11 differs from C++89/C++03 quite substantially, one might say they can be considered different languages. However this doesn't use any of the new C++11 features. It is equivalent to writing code in the C subset of C++ (which also has already happened here on codegolf.SE). Therefore the standard loophole would more be to use the language-X-subset of language Y (where here X=C++, Y=C++11). Another such pair, unrelated to C or C++, would be Pascal and Object Pascal. \$\endgroup\$ – celtschk Apr 6 '14 at 10:07
1
\$\begingroup\$

Prolog and PHP

Tx: writer.pl

start :-
    open('file', write, Str),
    read(In),
    write(Str,In),
    nl(Str),
    close(Str).

Rx: reader.php

<?php
echo file_get_contents('file');

Usage:

$ gprolog
['writer.pl'].
start.
hello.

And then:

$ php reader.php
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.