[asio-users] New to Sockets, data not being passed correctly
Brought to you by:
chris_kohlhoff
From: Tristan M. <TMayfield@Braintrace.com> - 2019-11-21 21:52:39
|
Hi everyone, I'm new to the mailing list. Let me know if my questions belong elsewhere. I'm currently setting up a local daemon on Ubuntu 18.04, it listens on a local Unix socket for input in the form of a JSON object, does some calculations on that object and sends the new, modified JSON object back via the same socket. My goal is to essentially have it interact with another daemon on the box and between the two of them they have network monitoring capabilities. The issues I'm having are that this process works well if I manually use netcat to send one object at a time, but if I try to make a client that sends and receives at a much higher rate, the JSON gets mangled and can't be parsed correctly. I first thought this was because my daemon is multithreaded, but I changed the code to only have a reader and writer thread that access the socket. I thought the OS made sockets thread safe, but perhaps it doesn't? Should I just make an "input" and "output" local socket? My second thought involves incorrect buffer sizes, do I need the exact size of the buffer to be read from the socket when reading? Sorry if these are newbie questions. Most of my previous socket experience is in Java. I'd be happy to send some example code of how I'm doing all this, both client and server side. Thanks! |