An example of processing read / write packets in C

I'm a little new to C, but I did my homework (some tutorials, books, etc.) and I need to program a simple server to handle requests from clients and interact with db. I went through the Beej Guide for network programming, but I'm a little unsure how to compose and process the different parts of the data sent back and forth.

For example, let's say a client sends some information that the server will put in several fields. How to combine this data for sending, and then split it on the server side?

Thanks,

Eric

+3
source share
3 answers

, : " , ?"

, , : , . , .

, , - , , "", "" "" " ", , .

, , . , , , ..

struct Person {
    char* name;
    int age;
    int heightInInches;
    // ... other fields ...
};

/. :

  • hton/ntoh
  • , , .
  • , 4B ( , , C , , ).

, , /, .

, . , , , send/recv?

+4

, - . , . , , , , , big-endian little-endian, 32- long 64- long, , , , - , .

, ( ) ( " " ) .

, , , .

, ntohs() ('n') ('h') "" ( 16-) htonl() host 'long' (32- ) - ..

- " UNIX, 1, Edn". -, .

+3

, . , , - xmls .

. , , , . .

The biggest advantage is that after you have the parser on the client side, even if you need to send some new information, they just need to agree on the tag name, which will be analyzed on the client side.

It helps me, I hope it helps too.

0
source

Source: https://habr.com/ru/post/1710839/


All Articles