简体   繁体   English

如何在随后出现HttpURLConnection的情况下打开套接字

[英]How to open a socket in anticipation of an ensuing HttpURLConnection

I'm working on an Android application that requires very quick responses from our server. 我正在开发一个Android应用程序,该应用程序需要我们服务器的快速响应。 We communicate using HttpURLConnections. 我们使用HttpURLConnections进行通信。 In an attempt to reduce latency, I'd like to "warm up" the connection by opening the socket when the user is actively using the application so that when we do get a request to send data, the connection will already be established (assuming the socket wasn't closed server side due to timeout). 为了减少延迟,我想通过在用户积极使用应用程序时打开套接字来“热身”连接,以便当我们收到发送数据的请求时,已经建立了连接(假设套接字由于超时未关闭服务器端)。 I believe that URL.openConnection() does not actually open this socket (despite its name) until data is actually sent. 我相信URL.openConnection()不会实际打开此套接字(尽管其名称),直到实际发送数据为止。 Is this correct? 这个对吗? If so, is there a better way to simply open a socket and pass that to another HTTPURLConnection later without sending data and have that socket stay open for the keep-alive time? 如果是这样,是否有更好的方法来简单地打开一个套接字,然后在不发送数据的情况下将其传递给另一个HTTPURLConnection,并使该套接字保持打开状态?

i think this migth help you 我认为这种力量可以帮助您

https://github.com/Gottox/socket.io-java-client https://github.com/Gottox/socket.io-java-client

its an IO Socket, mantains a conection with the server recieving data on the method "on", and you can send as well data trough "emit". 它的IO套接字,与服务器一起接收数据,方法为“ on”,并且可以通过“ emit”发送数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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