9
\$\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\$
2
  • 4
    \$\begingroup\$ Don't give up on this one! I like the idea, but it needs some more specific instructions. \$\endgroup\$ Mar 17, 2014 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\$ Mar 17, 2014 at 15:34

11 Answers 11

12
\$\begingroup\$

C and PERL communicating via keyboard status lights

My friend and I got inspired by this one last night.

We use Perl for the sender program and C for the receiver.

The medium of exchange was the keybord status lights!

Three virtual signal lines were used: Caps Lock, Num Lock and Scroll lock, being used as Clock, Serial Data, and Start Of Byte signals.

Data and signals

The sender program pulses those keyboard lights and the receiver polls them and checks the state. Data is sent serially as binary, in 8 bit bytes.

You can see the transmitter and receiver programs in operation, in the attached video, as well as the flashing of the lights during the transmission. Video of operation

Source for both programs is attached. Given the question requirements, we didn't try to minimize the size like we would in a normal golfing attempt.

C Code (receiver)

#include <X11/Xlib.h>
#include <stdio.h>
#include <unistd.h>

int main(void)
{
    Display* dpy = XOpenDisplay(":0");
    XKeyboardState x;
    char keys_return[32];
    int b = 0;
    while (1) {
        unsigned char output = 0;
        printf(" \b");
        fflush(stdout);
        while (XQueryKeymap(dpy, keys_return)) //wait for start signal
            if (keys_return[9] == 64) {
                break;
            }
        for (b = 0; b < 8; b++) {
            do {
                XGetKeyboardControl(dpy, &x);
            } while (!(x.led_mask & 1)); //wait for clock to be high
            if (x.led_mask & 2)
                output |= 128;
            if (b != 7)
                output >>= 1;
            do {
                XGetKeyboardControl(dpy, &x);
            } while ((x.led_mask & 1)); //wait for clock to be low
        }
        printf("%c", output);
    }
    XCloseDisplay(dpy);
    return 0;
}

PERL code (transmitter)

use X11::Xlib ':all';
use strict;
use warnings;
use feature 'say';
use Time::HiRes qw(sleep);

use constant {
    DATA  => 77,
    START => 78,
    CLOCK => 66
};

my $display = X11::Xlib->new;

sub transmit_str {
    my ($str) = @_;
    foreach my $char ( split( //, $str ) ) {
        my $ordchar = ord($char);
        for my $i ( 0 .. 7 ) {
            for my $j ( 0 .. 1 ) {
                if ( $i == 0 ) {
                    $display->fake_key( START, !($j) );
                }
                if ( $ordchar & 1 ) {
                    $display->fake_key( DATA, 1 );
                    $display->fake_key( DATA, 0 );
                }
                $display->flush;
                sleep(0.025) if(!$j);
                $display->fake_key( CLOCK, 1 );
                $display->fake_key( CLOCK, 0 );
                $display->flush;
                sleep(0.05);
            }
            $ordchar >>= 1;
        }
    }
}
while ( my $stdin = <STDIN> ) {
    transmit_str($stdin);
}
\$\endgroup\$
9
\$\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\$
3
  • \$\begingroup\$ Not exactly what I was asking for \$\endgroup\$
    – TheDoctor
    Mar 17, 2014 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\$ Mar 17, 2014 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, 2014 at 2:30
6
\$\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\$
1
  • 2
    \$\begingroup\$ Please mention and underline that you are using gawk features probably not present in most other awk implementations. Thanks! \$\endgroup\$
    – user19214
    Mar 18, 2014 at 0:07
5
\$\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\$
5
\$\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\$
4
\$\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\$
3
\$\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\$
1
  • \$\begingroup\$ Inspired choice of rx language! \$\endgroup\$
    – tomsmeding
    Mar 18, 2014 at 6:59
3
\$\begingroup\$

q and k

Receiver, rx.q, in q

\p 29010

Transmitter, tx.k, in k

.z.pi:{`::29010(-1;x)};
\$\endgroup\$
2
\$\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\$
2
  • 1
    \$\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, 2014 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, 2014 at 10:07
2
\$\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\$
0
\$\begingroup\$

VBS and Python

communicating over microphone and speakers in cleartext

Works astonishingly well out of the box

transmit

CreateObject("sapi.spvoice").Speak WScript.Arguments.Item(0)

receive

import speech_recognition as sr

r = sr.Recognizer()
m = sr.Microphone()

try:
    while True:
        print("listening")
        with m as source: audio = r.listen(source)
        try:
            value = r.recognize_google(audio)
            print("repeating: " + value)
        except sr.UnknownValueError:
            print("¯\_(ツ)_/¯")
except KeyboardInterrupt:
    pass

(this is 90% straight from the quickstart examples, might as well just run python -m speech_recognition) enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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