Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
- }
Add Comment
Please, Sign In to add comment