Created
October 1, 2008 10:23
-
-
Save ohac/14061 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 java.net._ | |
import java.io._ | |
import scala.actors.Actor | |
import scala.actors.Actor._ | |
object HTTPD { | |
def server = { | |
loop { | |
react { | |
case s :Socket => | |
val o = s.getOutputStream | |
val w = new BufferedWriter(new OutputStreamWriter(o, "UTF-8")) | |
w.write("HTTP/1.0 200 OK\r\n" + | |
"Content-Type: text/plain\r\n" + | |
"\r\n" + | |
"こんにちはScala\n") | |
w.flush | |
s.close | |
} | |
} | |
} | |
def listen = { | |
val sock = new ServerSocket(8080) | |
loop { | |
react { | |
case 'accept => | |
val csock = sock.accept | |
val s = link { server } | |
s ! csock | |
self ! 'accept | |
} | |
} | |
} | |
def main(args :Array[String]) { | |
val l = link { listen } | |
l ! 'accept | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment