I have a packet to be sent from client 1 to client 2 through a Http connection. Lets call this packet packet 1. I don’t expect any reply from client 2 for packet 1. I now want to send packet 2. If I attempt to write packet 2 to the connection without reading the reply sent for packet 1, I get an exception. Why should I read the response for packet 1, when I’m not interested in seeing what I get?
Share
If you are using HTTP, you need to conform to the HTTP protocol as set out in the HTTP Specification. That says that the client sends a request message to the server and the server sends a response. The client needs to read that response completely before it sends another request on the connection.
No. That would be a protocol violation. It might work for one or two requests, but eventually the server-to-client side of the connection would “back up” and things would break. HTTP is not supposed to work this way.
If you don’t want to conform to the requirements of HTTP, you should use a different protocol … or invent your own application-specific protocol.
It is not clear exactly why you are getting an exception immediately. (You don’t mention what the exception is, or what client-side HTTP library you are using.) But I expect that the exception is from the HTTP implementation, telling you that you are using the APIs incorrectly.