Guest User

Untitled

a guest
Feb 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import java.net._
  2. import java.io._
  3. import scala.actors.Actor
  4. import scala.actors.Actor._
  5.  
  6. object HTTPD {
  7. def server = {
  8. loop {
  9. react {
  10. case s :Socket =>
  11. val o = s.getOutputStream
  12. val w = new BufferedWriter(new OutputStreamWriter(o, "UTF-8"))
  13. w.write("HTTP/1.0 200 OK\r\n" +
  14. "Content-Type: text/plain\r\n" +
  15. "\r\n" +
  16. "こんにちはScala\n")
  17. w.flush
  18. s.close
  19. }
  20. }
  21. }
  22. def listen = {
  23. val sock = new ServerSocket(8080)
  24. loop {
  25. react {
  26. case 'accept =>
  27. val csock = sock.accept
  28. val s = link { server }
  29. s ! csock
  30. self ! 'accept
  31. }
  32. }
  33. }
  34. def main(args :Array[String]) {
  35. val l = link { listen }
  36. l ! 'accept
  37. }
  38. }
Add Comment
Please, Sign In to add comment