I’m communicating with a server and ideally I would want an input stream and an output stream always up. I receive unsolicited responses, so I always have to be ready to receive data on the input stream.
Before I dive in much further, I should say that whatever connection I make must be capable of supporting SSL.
The problem I’m encountering is when I open an HttpUrLConnection and send stuff from the Output stream, it won’t send the actual output until I open an input stream. If I open an input stream, it kills the output stream and there seems no was of recovering it once the stream is closed.
What would be the best way to implement my desired behavior? If maintaining both streams at once on one port is impossible, is there a way I could have two separate streams that share the connection via a sort of port lock/switch?
Is there a library for sending output without having to kill the output stream to signal the end of my request?
Http is a single request protocol.
You cannot (unless websocket) create a persistent connection using http(s). You need another protocol.
A basic socket can be used. It works mostly like an http connection except the url starts with socket://.
You simply open a connection, and then you can get the input stream and the output stream and use them.