您好我正在做一个连接到Twitter Streaming API的应用程序,我正在使用WS来建立这样的连接
WS.url(endpoint).withTimeout(-1).sign(OAuthCalculator(consumerKey, accessToken)).postAndRetrieveStream(parameters)(processResponse(_))
def processResponse(headers: ResponseHeaders) = {
Iteratee.foreach[Array[Byte]] { chunk =>
val chunkString = new String(chunk, "UTF-8")
println(chunkString)
}
}
我想知道是否有任何方法可以检测Twitter是否已关闭连接
谢谢!
答案 0 :(得分:0)
val future: Future[Unit] = WS.url(endpoint).withTimeout(-1).sign(OAuthCalculator(consumerKey, accessToken)).postAndRetrieveStream(parameters)(processResponse(_))
def processResponse(headers: ResponseHeaders) = {
Iteratee.foreach[Array[Byte]] { chunk =>
val chunkString = new String(chunk, "UTF-8")
println(chunkString)
}
}
future.map { _ =>
println("done")
}