Socket编程概念

一、网路套接字

  在通信过程中,套接字是成对存在的,该套接字内部借助两个缓冲区实现

  

二、网络字序

  1.存储方式

    大端法(网络):高位存低位,低位存高位

    小端法(本地):高位存高位,低位存低位

  2.网络字序和本地字序的转换  

   (1) htonl(uint32_t  hostlong)            本地---->网络            IP为32位

   (2) htons(uint16_t  hostshort)          本地---->网络            port为16位 

   (3) ntohl(uint32_t  netlong)              网络---->本地            IP为32位

   (4) ntols(uint16_t netshort)              网络---->本地            port为16位 

      l ---->32位长整形  s----->16短整型

   n----->network       h----->host

  一般主机为小端字节序,网络为大端字节序

猜你喜欢

转载自www.cnblogs.com/liunx1109/p/9661555.html
今日推荐