-
-
Save alandipert/127742 to your computer and use it in GitHub Desktop.
This file contains hidden or 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._ | |
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