Created
June 14, 2009 05:06
-
-
Save alandipert/129556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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