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

后端 未结 7 490
小蘑菇
小蘑菇 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:42

    Write can do what you want it to, but there's some things to be aware of:

    1: You may get a partial write that's not on an int boundary, so you have to be prepared to handle that situation

    2: If the code needs to be portable, you should convert your array to a specific endianess, or encode the endianess in the message.

    0 讨论(0)
提交回复
热议问题