LoginSignup
20
13

More than 5 years have passed since last update.

gopherだからgoでgopherしよう

Last updated at Posted at 2015-06-21

みなさん、gopherはご存知でしょうか。
gopherといったらやっぱり、プログラミング言語Goのマスコット、Gopherくんですよね!

でも今回はそれじゃなくて、1991年に開発された通信プロトコル、RFC1436 "Gopher" の話です。
今回はこのGopherをGoから使ってあげたいと思います。

Gopherとは

Gopher(ゴーファー)とは、インターネットがテキストベース(文字情報主体)のネットワークであった1991年に、アメリカ合衆国のミネソタ大学が開発したテキストベースの情報検索システム。
1993年頃から本格的になったWWWの普及や、Gopherそのものが日本語などマルチバイト文字環境に対応していなかったため、2013年1月現在はほとんど使われていない。
--- https://ja.wikipedia.org/wiki/Gopher

WWWや、httpが普及される前にあってみたいですね。完全に生前の技術です、オーパーツです。
しかも基本は70番ポートでやりとりして、返ってくるのはファイルの階層情報のみ、、、そうです、サーバシグニチャとかないんです。

では実際にやってみましょう。

やってみる

gopherについて書かれている記事は数えられるほどしかなく、特にamizeさんのhttp://amize.hatenablog.com/entry/2012/01/12/112212
この記事はすごくありがたかったです。日本語で書かれてるgopher記事は本当にないのでかなり助かりました。これからgopherを触ってみたい方は是非一読を!

では実際に実装してみました

package main

import (
    "fmt"
    "io/ioutil"
    "net"
)

func main() {
    conn, err := net.Dial("tcp", "gopher.quux.org:70")
    if err != nil {
        panic(err)
    }
    _, err = conn.Write([]byte("\r\n"))
    if err != nil {
        panic(err)
    }
    bytes, err := ioutil.ReadAll(conn)
    if err != nil {
        panic(err)
    }
    fmt.Println(string(bytes))
}

net.Dialでgopher.quux.orgの70番ポート(ちなみにこれくらいしか今生きているgopherサーバーはないみたいです。ちなみにこのgopher.quux.orgはhttpサーバーも兼ねてるので、下手するとHTTP 200 OKという今は帰って来てほしくない言葉が返ってきます)にTCP接続して、そこから改行を検知してます。2014年のGo1.4で1991年のgopherとつながる、、、ロマンがありますね。

実行結果は次のようです

iWelcome to gopher at quux.org! fake    (NULL)  0
i   fake    (NULL)  0
iThis server has a lot of information of historic interest, fake    (NULL)  0
ifunny, or just plain entertaining -- all presented in Gopher.  fake    (NULL)  0
iThere are many mirrors here of rare or valuable files with the fake    (NULL)  0
iaim to preserve them in case their host disappears.  PLEASE READ   fake    (NULL)  0
i"About This Server" FOR IMPORTANT NOTES AND LEGAL INFORMATION. fake    (NULL)  0
i   fake    (NULL)  0
0About This Server  /About This Server.txt  gopher.quux.org 70  +
1Archives   /Archives   gopher.quux.org 70  +
1Books  /Books  gopher.quux.org 70  +
1Communication  /Communication  gopher.quux.org 70  +
iThis directory contains the entire text of the book    fake    (NULL)  0
i"We the Media: Grassroots Journalism by the People, for the People"    fake    (NULL)  0
iby Dan Gillmor in various formats. fake    (NULL)  0
i   fake    (NULL)  0
iFeel free to download and enjoy.   fake    (NULL)  0
1Computers  /Computers  gopher.quux.org 70  +
1Current Issues and Events (Updated Apr. 23, 2002)  /Current    gopher.quux.org 70  +
1Development Projects   /devel  gopher.quux.org 70  +
0Gopher's 10th Anniversary  /3.0.0.txt  gopher.quux.org 70
1Government, Politics, Law, and Conflict    /Government gopher.quux.org 70  +
0How To Help    /How To Help.txt    gopher.quux.org 70  +
1Humor and Fun  /Humor and Fun  gopher.quux.org 70  +
1Index to Quux.Org  /Archives/index gopher.quux.org 70
1Internet   /Internet   gopher.quux.org 70  +
1Other Gopher Servers   /Software/Gopher/servers    gopher.quux.org 70
1People /People gopher.quux.org 70  +
1Reference  /Reference  gopher.quux.org 70  +
1Software and Downloads /Software   gopher.quux.org 70  +
1The Gopher Project /Software/Gopher    gopher.quux.org 70
0What's New /whatsnew.txt   gopher.quux.org 70  +

行の一番前にある値は、iがインフォメーション、0がプレーンテキスト、1が階層を表しています。ほかにも2がCSO search queryだったり、8がtelnet session pointerだったりするのですが、なにせ生きてる鯖がこれしかないので、実際にそれを確認することはできません、、、
あと、この行の最後にある + なのですが、これが仕様のどこにも載ってなくて、一体何なのか、わかりません、gopherの仕様自体もかなりゆるゆるです。

gopherはとてもシンプルなので、とても簡単に実装できますね
以上でgopherなのでgoでgopherする話でした!gopherを感じたくなった時は是非お試しあれ!

(1時間前に同じような内容の全くトンチンカンな記事を投稿してしまったので、削除してあげなおしました。申し訳ないです)

20
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
13