简体   繁体   中英

Streaming data to/from Play framework on an open connection

I need to send a stream of data to Play server. The length of the stream is unknown and I need to get a response every line break \\n or for every several lines. Rather then wait for the whole data to be sent.

Think of the following usecase:
lets say i'm intended to write a console application, that when launched, connects to my web server, and all the user input are being sent to play on every line break, and gets responded asynchronously. All above should be performed on a single connection, ie I don't want to open a new connection on every request I send to Play (a good analog would be 2 processes communicating through 2 pipes) .
What is the best way to achieve this?
And is it possible to achieve with a client that communicates with the server only via http (with a single http connection)?

EDIT:
my current thoughts on how to approach this are as follows:
i can define a new BodyParser[Future[String]] which is basically an Iteratee[Array[Byte],Future[String]] . while the parsing takes place, i can compute the result asynchronously and the action can return the result as ChunkedResult in the future's onComplete method.

does this sound like the right approach?
any suggestions on how to achieve this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM