0

I am sending TCP packets just few bits each (one line of text or so). I am sending them to remote server via HTTP proxy however for some reason when the connection with the proxy is slow or interrupted to the server arrives just a fragment of the packet and not entire packet and it causes exceptions on the server side, how it that posible ? Is there any way on the client side how to prevent sending fragment of the packet instead of entire packet ?

Example: I am trying to send this packet:

packetHead: id (1-99)
integer: 1
short: 0
byte: 4

And in my case sometimes happens that to the server arrives just packetHead and integer and the rest of the packet is lost somewhere when the connection with the proxy is bad.

I have no access to modify server source code so I need to fix it on the client side.

Thanks for any tips.

1
  • Without knowing your server, your proxy and even your sending code, it's only fishing in the dark. If you don't use an exotic proxy and you can exclude a server side error then, I would say that sometimes your sending code does only partially fill the tcp send buffer before you trigger the transport. But that's only a wild guess. TCP is a well tested protocol and standard proxies would hopefully not produce such an error, even if the message was fragmented, which I doubt. Have you checked it with a sniffer? Commented Oct 15, 2015 at 15:55

1 Answer 1

1

Please show how you send your data. Every time I had a similar problem it was my fault for not flushing the stream. Especially if the stream is compressed you need to call close/complete on the GZIP or similar object to actually send out everything.

Sign up to request clarification or add additional context in comments.

7 Comments

Here is how I send data, but as I said when I use direct connection it works well, only when I am socketed via proxy there are problems. pastebin.com/zt53Ch4x
add one more line at the end: 'serverOut.flush();' and see if it helps.
I have tried it but still I got errors on the server side, that the packet arrived in malformed format, but I have realized that this happens only on some proxies I am not sure it it is random or there are specific proxy adresses that are modifying somehow the packet ? I am using public proxies to test.
On the server side there is netty and it gives me timeout exceptions for some reason, like this one: pastebin.com/t8MNZcAB
Don't just try. That flush call at the end should be there always. I do not know what class or implementation serverOut is ( is it a plain stream from a socket or more specific to an Htttp connection) but your data is traveling over an Http proxy.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.