Skip to content

Instantly share code, notes, and snippets.

@alandipert
Forked from anonymous/Qbert.scala
Created June 11, 2009 06:38
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/127742 to your computer and use it in GitHub Desktop.
Save alandipert/127742 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._
import scala.xml._
//case classes
case class Request(s:Socket)
// actor definition
object Handler extends Actor {
def act = {
loop {
react {
case Request(s) => {
val out = new PrintWriter(s.getOutputStream);
out.println("HTTP/0.9 200 OK\r\nContent-Type: text/html; charset=ISO-8859-1\r\n")
out.println(<h1>wsup from scala, dawg!</h1>.toString)
out.close()
}
}
}
}
}
// application
object Qbert extends Application {
try {
val listener = new ServerSocket(9876)
Handler.start
while(true)
Handler ! Request(listener.accept())
} catch {
case e: Exception => println("Couldn't listen on 9876")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment