Home  >  Q&A  >  body text

网络编程 - C++ socket编程中,read/write 参数类型不同会怎样?

C++ socket编程中,如果

其中一端是 write(fd, new char[10], 10).
而另一端是 read(fd, new int[5], 5)
请问return的数值是什么?-1? 5?

巴扎黑巴扎黑2715 days ago629

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-17 15:26:04

    Socket does not know your data type and treats it as a char sequence. If the types are inconsistent, it does not matter. Anyway, it only guarantees that the byte sequence is the same. It is equivalent to (int*)(new char[10]).

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 15:26:04

    In a non-good network environment (for example, LAN), the return value should be a random value.
    Because they have no relationship in the first place. .

    reply
    0
  • Cancelreply