How to deal with erroneous length headers for packets in TCP stream in Erlang? -


I am receiving a message at TCP using the message gen_tcp in Erlang. The stream is divided into packets using 4 byte length headers, as specified by the {packet, 4} option. This is how I gen_tcp: listen / 2 :

  gen_tcp: listen (port, [binary, inet, {active, one time}, {packet, 4 }]).   

As you can see, I am using the {active, one time} option so that I move my packet without flooding from the process mailbox. Can i It works fine until the length header is correct. If it is not, then anything can happen, so I want to deal with the possibility of some wrong packet.

It is a bit difficult because I am actually working with a stream. It would be OK to ignore the wrong packets, but how do I get Arlong to leave these packets and identify the following packets? How is this problem usually handled?

Is it better to use delimiter? I have seen some other packet options for gen_tcp . Specifically the following:

  asn1 | CDR | Sunrom | FCG | TPKT | Line   

Only one I really understand the meaning of line , but I do not think this would be a good option. I hope to achieve the packages sent in Objective-C and to get the packages created, which I am not familiar with, which has many different types of data, not only the string

The main reason is What is a bad packet?

Anyone can specify 4 byte size, so if someone is sent: Hello \ n

Actually get: 0x48656c6c as the header header, indicating That frame 1214606444 bytes "o \ n" and then you will hang

You can set {packet_size, 1024} (or whatever) to keep from assigning 1.2gb to "Hello"

It is not certain that he leaves the error or drops.

There is actually no way from bad framing in TCP because the messages are divided into transit.

If you {PACKET, N} then you have to control your own division, you will find lines of text, you should know when the message ends.

If you control the customer / service, you may want to use {PACKET, HT} or a more complete solution like

, then you have the customer Submit requests (body can still do by binary), and worse with framework deals request for you.

If you need a bi-directional channel, web sites can still be fine (assuming you have a websocket lib in Objective-C)

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -