1
\$\begingroup\$

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.
\$\endgroup\$

closed as unclear what you're asking by Mego, Toto, Shaggy, Don't be a x-triple dot, Stephen Jul 3 '17 at 11:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Is there a specific host we need to send to? \$\endgroup\$ – Kevin Cruijssen Jul 3 '17 at 7:23
  • \$\begingroup\$ @KevinCruijssen you can use any, but it will be able to recive message \$\endgroup\$ – Евгений Новиков Jul 3 '17 at 7:24
  • \$\begingroup\$ Could you give a valid example-host? \$\endgroup\$ – Kevin Cruijssen Jul 3 '17 at 7:43
  • 1
    \$\begingroup\$ @KevinCruijssen localhost \$\endgroup\$ – Евгений Новиков Jul 3 '17 at 7:52
  • 5
    \$\begingroup\$ 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. \$\endgroup\$ – Martin Ender Jul 3 '17 at 8:12
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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 ^^' \$\endgroup\$ – V. Courtois Jul 3 '17 at 8:41
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Kevin Cruijssen Jul 3 '17 at 11:20

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