Skip to content

Instantly share code, notes, and snippets.

@limpid-kzonix
Created April 23, 2019 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save limpid-kzonix/e0028c7b9b1a3cd341c8a927455642c2 to your computer and use it in GitHub Desktop.
Save limpid-kzonix/e0028c7b9b1a3cd341c8a927455642c2 to your computer and use it in GitHub Desktop.
simple Scala TCP server
import akka.actor._
import java.net.InetSocketAddress
import akka.util.ByteString
class TCPServer(port: Int) extends Actor {
override def preStart {
IOManager(context.system).listen(new InetSocketAddress(port))
}
def receive = {
case IO.NewClient(server) =>
server.accept()
case IO.Read(rHandle, bytes) => {
val byteString = ByteString("HTTP/1.1 200 OK\r\n\r\nOK")
rHandle.asSocket.write(byteString)
rHandle.close()
}
}
}
object Application {
def main(args: Array[String]) {
val port = 8000
ActorSystem().actorOf(Props(new TCPServer(port)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment