Recently need to write a C composed of server-side and C # client to interact with the software, just beginning to write when the C # side of the parsing occurred in the fault, after careful study found that the cause is the sender transmission too fast, there is a so-called sticky packet phenomenon. That is, receive () on the C # side. This function returns data that is linked to multiple structures, which of course cannot be parsed. My solution is as follows:
list<byte[]> Listb = new list<byte[]> (), .... int recv = newclient. Receive (B1); for (int x = 0; x < RECV/12; + +) {byte[] b2 = new Byte[12];int i=0;for (int lc = x *); LC < X * 12 + 12; lc++) {B2[i] = b1[lc];i++;} Listb. ADD (B2);}
This allows you to directly parse the elements in the LISTB, directly
foreach (var i in Listb) {...}.... }
However, in the subsequent analysis there is still a problem, my structure elements in the second half of the number is not sent to send the end of the transmission, nor garbled. Later, after careful examination found that because the server side is written by C, the client is written in C #, on both sides in a different environment. When C declares a struct, there is a phenomenon of so-called "memory Alignment". In this way, there will be a middle part of the conversion where the binary is generated by the compiler to populate the numbers. My solution is to populate it with 0 bytes (PS. Finally know why the protocol format for RIP is so weird). After the fill is complete, the structure size is unchanged and the C # end resolves successfully.
C and C # socket cross-platform communication transport fabric body