Groupsock (Port)--live555 source Read (iv) network
- Groupsock (Port)--live555 source Read (iv) network
- Brief introduction
- Definition of the Port class
- Port construction and global << operator overloading
This article by Mob Lym fabricated, welcome reprintblog.cnblogs.net/oloroso
This article by Mob Lym fabricated, welcome reprintmy.oschina.net/oloroso
Brief introduction
The port class is used to save the network port, the computer network port generally has two meanings, respectively is the physical sense network device interface and the logical sense port. This refers to the logical port (specifically the TCP/IP
port in the protocol), the range of the port is 0
to 65535
(u_int16_t of the Representation range).
Port
Class has only one data member to portNumBits fPortNum
hold the port value. The saved is expressed in the network byte order. The network byte order is the big endian.
The byte order is slightly mentioned here. The byte order is divided into 大端序
and 小端序
. Take the carcass here, which fPortNum
is 16bits
width, which accounts for two bytes. If it represents the memory block 0x1000
and 0x1001
the two bytes, and the contents of the storage is 0x5678, then is that byte representing 0x56
that byte 0x78
? This involves the problem of byte order. Usually the low address is saved and the high address is called the small end sequence. The reverse is the big-endian sequence.
memory Address |
Small-order representation 0x5678 | Big
endian indicates 0x5678 |
0x1001 |
0x56 |
0x78 |
0x1000 |
0x78 |
0x56 |
Definition of the Port class
1 typedef u_int16_t Portnumbits;2 classPort {3 Public:4Port (portnumbits num/*In host byte order*/);5 6Portnumbits num ()Const //In network byte order7 {8 returnFportnum;9 }Ten One Private: APortnumbits Fportnum;//stored in network byte order - #ifdef IRIX -Portnumbits filler;//hack to overcome a bug in IRIX C + + compiler the #endif -};
The construction of port and the global
<<
Operator overloading
Construction is the assignment of the internal fPortNum
, note that the time of assignment is converted to the network byte order. htons
The function is host to network,return short
meant to convert the parameters from the num
host order to the network order (possibly with the same host sequence and network order). When all the arguments are passed, the biography is converted to the network sequence.
1 /* */) {2 fportnum = htons (num); 3 }
Overloading the global <<
is to use BasicUsageEnvironmen
the T object to output the port value. The function here ntohs
is an htons
inverse operation that converts the network byte order to the host byte order.
1 operator Const port& p) {2 return s << Ntohs (P.num ()); 3 }
Groupsock (Port)--live555 source Read (iv) network