weixin_42207676 2008-06-23 12:30
浏览 216
已采纳

请教一个关于http连接keep alive的问题!

server用的是jetty,client用apache的commons-httpclient来执行method 。

目前我知道了 用 method.setRequestHeader("Connection" , "Keep-Alive" or "close") 来控制是否保持连接。

现在没弄懂的地方: 在保持连接的情况下,如何设置自动断开的时间? 比如, 我要设置keep alive 1分钟,如果这期间没有数据的传输,那么就断开连接。

请问该怎么设置? request里设置,还是jetty需要什么改配置?

  • 写回答

2条回答 默认 最新

  • hjgundam 2008-06-23 15:20
    关注

    可以在jetty里面设的

    org.mortbay.jetty.nio.SelectChannelConnector#setMaxIdleTime()方法就是设socket通信的过期时间

    javaDoc是这样的:

    Description copied from class: AbstractConnector
    Set the maximum Idle time for a connection, which roughly translates to the Socket.setSoTimeout(int) call, although with NIO implementations other mechanisms may be used to implement the timeout. The max idle time is applied:
    When waiting for a new request to be received on a connection
    When reading the headers and content of a request
    When writing the headers and content of a response
    Jetty interprets this value as the maximum time between some progress being made on the connection. So if a single byte is read or written, then the timeout (if implemented by jetty) is reset. However, in many instances, the reading/writing is delegated to the JVM, and the semantic is more strictly enforced as the maximum time a single read/write operation can take. Note, that as Jetty supports writes of memory mapped file buffers, then a write may take many 10s of seconds for large content written to a slow device.
    Previously, Jetty supported separate idle timeouts and IO operation timeouts, however the expense of changing the value of soTimeout was significant, so these timeouts were merged. With the advent of NIO, it may be possible to again differentiate these values (if there is demand).

    所以只需要在xml配置文件里面设定这个值就可以了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)