C and C # socket cross-platform communication transport fabric body

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.