Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created June 14, 2009 05:06
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 alandipert/129556 to your computer and use it in GitHub Desktop.
Save alandipert/129556 to your computer and use it in GitHub Desktop.
import scala.actors.Actor
import scala.actors.Actor._
import java.net.{InetAddress,ServerSocket,Socket,SocketException}
import java.io._
case class Start(m:String)
case class Request(s:Socket)
object Qbert extends Actor {
def main(args: Array[String]) {
val listener = new ServerSocket(8081)
Qbert.start
Qbert ! Start("Starting")
Qbert ! "wtf"
while(true)
Qbert ! Request(listener.accept())
}
def act = {
loop {
react {
case Request(s) => {
val out = new PrintWriter(s.getOutputStream)
out.print("HTTP/0.9 200 OK\r\nContent-Type: text/html;\r\n\r\n")
out.print("<html><head><title>Qbert Test</title></head><body><h1>Yo, it's "+new java.util.Date+"</h1></body></html>")
out.close()
}
case Start(m) => println(m)
case _ => println("i received an unknown message")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment