Skip to content

Instantly share code, notes, and snippets.

@7yan00
Last active August 29, 2015 14:23
Show Gist options
  • Save 7yan00/d717df36469f9388b46b to your computer and use it in GitHub Desktop.
Save 7yan00/d717df36469f9388b46b to your computer and use it in GitHub Desktop.
みなさん、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を触ってみたい方は是非一読を!
では実際に実装してみました
```go
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)
}
fmt.Println(conn)
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とつながる、、、ロマンがありますね。
実行結果は次のようです
```
&{{0xc208010070}}
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を感じたくなった時は是非お試しあれ!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment