Last active
April 29, 2018 05:44
-
-
Save kiritsuku/6b2661a0df512eb321e9 to your computer and use it in GitHub Desktop.
Simple TCP client
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 scala.io.StdIn | |
import scala.util._ | |
import akka.actor._ | |
import akka.stream._ | |
import akka.stream.scaladsl._ | |
import akka.stream.stage._ | |
import akka.util._ | |
object SimpleTcpClient extends App { | |
implicit val client = ActorSystem("SimpleTcpClient") | |
implicit val materializer = ActorMaterializer() | |
val address = "127.0.0.1" | |
val port = 6666 | |
val connection = Tcp().outgoingConnection(address, port) | |
val flow = Flow[ByteString] | |
.via(Framing.delimiter(ByteString("\n"), maximumFrameLength = 256, allowTruncation = true)) | |
.map(_.utf8String) | |
.map(println) | |
.map(_ ⇒ StdIn.readLine("> ")) | |
.map(_+"\n") | |
.map(ByteString(_)) | |
connection.join(flow).run() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment