How do I send an array of integers over TCP in C?

后端 未结 7 508
小蘑菇
小蘑菇 2020-12-17 06:39

I\'m lead to believe that write() can only send data buffers of byte (i.e. signed char), so how do I send an array of long integers using the C write()

7条回答
  •  自闭症患者
    2020-12-17 07:29

    Declare a character array. In each location of the array, store integer numbers, not characters. Then you just send that.

    For example:

    char tcp[100];
    
    tcp[0] = 0;
    tcp[1] = 0xA;
    tcp[2] = 0xB;
    tcp[3] = 0xC;
    .
    .
    
    // Send the character array
    write(sock, tcp, sizeof(tcp));
    

提交回复
热议问题