Quine over network

1

Write a program, that sends its own source code over network.

Network example is TCP/UDP or web socket. Ethernet, Bluetooth, Wi-Fi and internet over USB are allowed.

No need to write receiver program. You can use any encoding protocol, but decoder will be realizable.

Rules

  • Network is not a stdout, screen, USB, UART, GPIO or same.
  • The program must be at least 1 byte long.
  • No input or accessing source from file system.
  • No extra software to send stdout to network like ssh.
  • This is , shortest code wins.

Евгений Новиков

Posted 2017-07-03T07:16:11.430

Reputation: 987

Question was closed 2017-07-03T11:16:50.600

Is there a specific host we need to send to? – Kevin Cruijssen – 2017-07-03T07:23:02.453

@KevinCruijssen you can use any, but it will be able to recive message – Евгений Новиков – 2017-07-03T07:24:41.327

Could you give a valid example-host? – Kevin Cruijssen – 2017-07-03T07:43:06.953

1@KevinCruijssen localhost – Евгений Новиков – 2017-07-03T07:52:18.113

5

This seems like the kind of generalised quine where the quine part adds nothing to the networking part and the networking part adds nothing to the quine part.

– Martin Ender – 2017-07-03T08:12:32.697

does unclear means boring? – Евгений Новиков – 2017-07-03T14:12:10.933

Answers

3

Java 8, 662 bytes

import java.io.*;import java.util.*;interface M{static void main(String[]a)throws Exception{String s="import java.io.*;import java.util.*;interface M{static void main(String[]a)throws Exception{String s=%c%s%1$c,x=s=s.format(s,34,s);for(List l=Arrays.asList(x.split(%1$c%1$c));!x.equals(s);s=s.join(%1$c%1$c,l));ObjectOutputStream o=new ObjectOutputStream(new java.net.Socket(%1$clocalhost%1$c,0).getOutputStream());o.writeObject(s);o.flush();}}",x=s=s.format(s,34,s);for(List l=Arrays.asList(x.split(""));!x.equals(s);s=s.join("",l));ObjectOutputStream o=new ObjectOutputStream(new java.net.Socket("localhost",0).getOutputStream());o.writeObject(s);o.flush();}}

Creating a in Java is verbose as F... >.>

Explanation:

'Try it' here. (Will result in java.net.SocketException: Permission denied.)

import java.io.*;              // Required import for ObjectOutputStream
import java.util.*;            // Required import for List and Arrays
interface M{                   // Class
  static void main(String[]a)  //  Required main-method
      throws Exception{        //  required throws for the Stream and Socket
    String s="import java.io.*;import java.util.*;interface M{static void main(String[]a)throws Exception{String s=%c%s%1$c,x=s=s.format(s,34,s);for(List l=Arrays.asList(x.split(%1$c%1$c));!x.equals(s);s=s.join(%1$c%1$c,l));ObjectOutputStream o=new ObjectOutputStream(new java.net.Socket(%1$clocalhost%1$c,0).getOutputStream());o.writeObject(s);o.flush();System.out.println(s);}}",
                               //   Quine-String
     x=s=s.format(s,34,s);for(List l=Arrays.asList(x.split(""));!x.equals(s);s=s.join("",l));
                               //   Quine-magic
    ObjectOutputStream o=new ObjectOutputStream(new java.net.Socket("localhost",0).getOutputStream());
                               //   Output stream to http://localhost:0000/
    o.writeObject(s);          //   Write to the output stream
    o.flush();                 //   And send it
  }                            //  End of main-method
}                              // End of class
  • The String s contains the unformatted source code.
  • %s is used to input this String into itself with the s.format(...).
  • %c, %1$c and the 34 are used to format the double-quotes.
  • s.format(s,34,s) puts it all together

Slightly modified with print to prove it's a quine:
Try it here.

Kevin Cruijssen

Posted 2017-07-03T07:16:11.430

Reputation: 67 575

Well is this considered as a quine? Sorry, I'm new to this. But you've just copypasted your code in a string you print afterwards >_< I was seeing quine as some complicated algorithm playing with generated bytecode. +1 though ^^' – V. Courtois – 2017-07-03T08:41:29.443

1

@V.Courtois Thanks for the +1. :) Although most programming languages have a built-in for quines, Java does not. Pasting the entire code into a String and using x=s=s.format(s,34,s);for(List l=Arrays.asList(x.split(""));!x.equals(s);s=s.join("",l)); is a.f.a.i.k. one of the few ways to actually make a 'quine' in Java. Currently this is still acceptable as a quine, although it has been mentioned here in the "Eval quines" section of this Meta post, with the question if we should still allow this: We need a new proper quine definition. No conclusion of it yet.

– Kevin Cruijssen – 2017-07-03T11:20:13.983