Skip to content

Instantly share code, notes, and snippets.

@cqfd
Created February 3, 2015 15:11
Show Gist options
  • Save cqfd/b95a306bc54f72699c6e to your computer and use it in GitHub Desktop.
Save cqfd/b95a306bc54f72699c6e to your computer and use it in GitHub Desktop.
scalaz-stream echo server
import java.net.InetSocketAddress
import scala.concurrent.Task
import scalaz.stream._
object Main {
def main(args: Array[String]): Unit = {
val address = new InetSocketAddress(45678)
implicit val cg = nio.DefaultAsynchronousChannelGroup
val s: Process[Task, Process[Task, Unit]] = nio.server(address).map { client =>
client.flatMap { ex =>
ex.read.to(ex.write).onFailure { e => Process.empty }
}
}
merge.mergeN(s).run.run
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment