It seems to me you can't use .read() with no arguments to read data that is not line-oriented and is not the whole transmission either. You must use .read(N), where N is a number of bytes. Then you parse what you get and decide on a suitable value of N for the next read. Rinse and repeat.
It's late and I may be writing nonsense... Best, Luciano On Thu, Jul 30, 2015 at 5:39 PM, Wellington Cordeiro <[email protected]> wrote: > I'm currently working on a project where we need to implement a protocol on > top of TCP, we're attempting to use the streams API and we have success > connecting to a server and sending messages over the socket. What's causing > trouble though is receiving messages back, since we don't know ahead of time > the size of the response we're calling read() with no arguments and we'll > get the first response just fine, but the next response will be chopped up. > > For example: > > We send a message like > 8=FIX.4.3\x019=63\x0135=5\x0149=DEMO.ZION2_P.FIX\x0156=ABFX\x0134=4\x0152=20150730-18:42:07.013\x0110=130\x01 > > to the server, and it responds with something similar in format with no > trouble. However, when we send a second message, the response will be > chopped into > just the "8" and then after we send a third message the other chunk of the > second response will come through like > > =FIX.4.3\x019=63\x0135=5\x0149=DEMO.ZION2_P.FIX\x0156=ABFX\x0134=4\x0152=20150730-18:42:07.013\x0110=130\x01 > > I can add some code examples if needed but I think I just need help with > understanding how to read() continuously since the documentation examples > are just reading > single lines or to the EOF. -- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Professor em: http://python.pro.br | Twitter: @ramalhoorg
