Created
February 22, 2021 15:53
-
-
Save johanandren/6863be0f27782810c0b2044a3ae8f98c 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 akka.actor.ActorSystem | |
import akka.stream.scaladsl.Flow | |
import akka.stream.scaladsl.Tcp | |
import akka.util.ByteString | |
object TcpServerOneResponseThenComplete2 { | |
def main(args: Array[String]): Unit = { | |
implicit val system = ActorSystem() | |
import akka.stream.scaladsl.Framing | |
val framing = Framing.delimiter(ByteString("\n"), 1024) | |
Tcp().bind("127.0.0.1", 9999, halfClose = true).runForeach { incomingConnection => | |
incomingConnection.handleWith(Flow[ByteString] | |
.via(framing) | |
.take(1) | |
.map { firstFrame => | |
println(s"Request: ${firstFrame.utf8String}") | |
ByteString("Response\n") | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment