Skip to content

Instantly share code, notes, and snippets.

@irl
Created August 20, 2012 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irl/3406222 to your computer and use it in GitHub Desktop.
Save irl/3406222 to your computer and use it in GitHub Desktop.
Fetching a TCP stream for output over Gopher and HTTP
<?php
header('Content-Type: image/gif');
$fp = fsockopen("marang.room205.org", 8091, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
from pygopherd.handlers.pyg import PYGBase
from pygopherd.gopherentry import GopherEntry
from socket import *
class PYGMain(PYGBase):
def canhandlerequest(self):
return 1
def getentry(self):
entry = GopherEntry(self.selector, self.config)
entry.type = 'g'
entry.mimetype = 'image/gif'
entry.name = 'Room 205 Webcam'
entry.setea('VIEWS', 'image/gif')
entry.setgopherpsupport(1)
return entry
def write(self, wfile):
host = 'marang.room205.org'
port = 8091
s = socket(AF_INET, SOCK_STREAM)
s.connect((host, port))
while True:
wfile.write(s.recv(1024))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment