Working on a chat server, I need to receive json via gen_tcp in erlang.
One way is to send a 4byte int header which is a good idea so i can also reject messages from clients if they exceed the max length but add complexity on client side. Another way is to read line, should work too for json if i am not wrong.
Third idea is to read json using depth tracking (counting '{' maybe?) That way i can also set max message length and make client code less complex. How can i do it specially with erlang i.e. check number of square brackets opened and keep receiving till last closes? or if its even a good idea? How does xmpp and other messaging protocols handle this problem?