Blackberry HttpConnection 超时
在我的 Blackberry 4.5 项目中,我通过 Connector.open 创建 HttpConnection。如果我通过 MDS 连接,我可以在 URL 的附加参数中指定 ConnectionTimeout。如果使用直接 TCP 连接或 TCP over WiFi,如何指定超时?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据这篇知识库文章,无法为 MDS 以外的传输指定连接超时值。
According to this KB article, it's not possible to specify a connection timeout value for transports other than MDS.
在某些情况下,可以使用 通过套接字的 Http 和 SocketConnectionEnhanced 与 READ_TIMEOUT 选项:
In some cases it's possible to use Http over Socket and SocketConnectionEnhanced with READ_TIMEOUT option:
根据官方文档
从 BlackBerry 智能手机建立传输控制协议 (TCP) 连接时,默认连接超时为 2 分钟。该值考虑了 BlackBerry 智能手机被授予访问权限以在无线网络上发送数据以及连接通过无线网络通过 Internet 传输到目标服务器并再次返回所需的时间。在某些情况下,该值太长。通过 BlackBerry® Mobile Data System (BlackBerry MDS) Connection Service 建立套接字或超文本传输协议 (HTTP) 连接时,可以将超时值设置为低于 BlackBerry MDS Connection Service 中配置的值。默认情况下,该值为 2 分钟。无法超出服务器上配置的限制。使用 ConnectionTimeout 参数指定超时值。该参数接受以毫秒为单位的数值。以下是超时值为 1 分钟的 HTTP 连接示例:
StreamConnection s = (StreamConnection)Connector.open("http://myserver.com/mypage.html;ConnectionTimeout=60000;deviceside=false");
HttpConnection httpConn = (HttpConnection)s;
注意:直接 TCP 连接或通过无线应用协议 (WAP) 网关的连接不支持 ConnectionTimeout 参数。只有通过 BlackBerry MDS Connection Service 建立的 TCP 连接支持此参数。
请参阅官方BB链接
As per official document
When making a Transmission Control Protocol (TCP) connection from a BlackBerry smartphone, the default connection timeout is 2 minutes. This value takes into consideration the possible time it can take a BlackBerry smartphone to be granted access to send data on the wireless network, and for the connection to travel over the wireless network over the Internet to the destination server and back again. In some circumstances, this value is too long. When making a socket or Hypertext Transfer Protocol (HTTP) connection through the BlackBerry® Mobile Data System (BlackBerry MDS) Connection Service, it is possible to set the timeout value to a lower value than the value that is configured in the BlackBerry MDS Connection Service. By default, the value is 2 minutes. It is not possible to extend beyond the limit configured on the server. Use the ConnectionTimeout parameter to specify the timeout value. This parameter accepts a numerical value in milliseconds. The following is an example of an HTTP connection with a timeout value of 1 minute:
StreamConnection s = (StreamConnection)Connector.open("http://myserver.com/mypage.html;ConnectionTimeout=60000;deviceside=false");
HttpConnection httpConn = (HttpConnection)s;
Note: The ConnectionTimeout parameter is not supported by direct TCP connections or connections through a Wireless Application Protocol (WAP) gateway. Only TCP connections, made through the BlackBerry MDS Connection Service, support this parameter.
Please see the official BB link
http://supportforums.blackberry.com/t5/Java-Development/Control-the-connection-timeout-for-TCP-connections-through-the/ta-p/445851