fda6625f8803 — QuintillusCFC 5 years ago
First version.  Fetches a Gopher page, at least so long as there's only one server reply.
3 files changed, 75 insertions(+), 0 deletions(-)

A => .hgignore
A => pom.xml
A => src/main/java/com/ajtjp/gopherarchiver/Gopher.java
A => .hgignore +5 -0
@@ 0,0 1,5 @@ 
+\.orig$
+\.orig\..*$
+\.chg\..*$
+\.rej$
+\.conflict\~$

          
A => pom.xml +13 -0
@@ 0,0 1,13 @@ 
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.ajtjp</groupId>
+    <artifactId>GopherArchiver</artifactId>
+    <version>0.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+</project>
  No newline at end of file

          
A => src/main/java/com/ajtjp/gopherarchiver/Gopher.java +57 -0
@@ 0,0 1,57 @@ 
+
+package com.ajtjp.gopherarchiver;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import javax.net.SocketFactory;
+
+/**
+ *
+ * @author Andrew
+ */
+public class Gopher {
+    public static void main(String[]args) {
+        try {
+            SocketFactory.getDefault();
+            Socket s = new Socket("66.166.122.165", 70); //floodgap
+//            Socket s = new Socket("205.166.94.16", 70);   //SDF
+//            Socket s = new Socket("sdf.org", 70);
+            OutputStream os = s.getOutputStream();
+//            byte[] newline = new byte[2];
+//            newline[0] = 13;
+//            newline[1] = 10;
+            byte[] newline = new byte[3];
+            newline[0] = 49;
+            newline[1] = 13;
+            newline[2] = 10;
+            os.write("\r\n".getBytes());
+//            os.write("/gopher/proxy\r\n".getBytes());   //floodgap
+//            os.write("/users/sanjuro/indian-food\r\n".getBytes());
+//            os.write("/users/sanjuro/indian-food/aam-ki-launji.txt\r\n".getBytes());
+//            os.write("\r\n".getBytes());
+            os.flush();
+//            Thread.sleep(1000); //seems to need to wait for the server to respond...
+            InputStream is = s.getInputStream();
+            boolean replyArrived = false;
+            for (;;) {
+                if (is.available() == 0 && !replyArrived) {
+//                    System.out.println("zzz...");
+                    Thread.sleep(10);
+                    continue;
+                }
+                while (is.available() > 0) {
+                    byte[] buffer = new byte[is.available()];
+                    int actual = is.read(buffer);
+                    String valueRead = new String(buffer, "Windows-1252");
+                    System.out.println(valueRead);
+                }
+                break;
+            }
+        }
+        catch(IOException | InterruptedException ex) {
+            System.err.println("IO Exception :(");
+        }
+    }
+}