1. Socket Communication TCP Way General Flowchart
Server client
Socket () socket ()
| | |
| ------------------------- setsockopt () --------------------- - |
| | |
Bind () connect ()
| | |
| | |
Listen () rv () / send () / write ()
|
|
accept ()
|
|
|
RECV () / send () / read ()
SETSOCKOPT Available Level is SOL_Socket:
Option is: SO_REUSEADDR option is to implement port heavy binding
Other options can be used or not.
2. Socket Communication UDP Mode General Flowchart
Server client
Socket () socket ()
| | |
| ------------------------- setsockopt () --------------------- - |
| | |
Bind () sendto ()
|
|
Recvfrom ()
If it is broadcast, setsockopt's available Level is SOL_SOCKET:
Option is: so_broadcast option is that the socket is used for broadcast.
The Sendto address can be: 255.255.255.255 restricted address
NetID.255.255 (class B address) All subnets under the network number
10.128.1.255 (class B address) This 1 subnet broadcast
10.128.255.255 (class B address) All subnet broadcast
If multicasting is setsockopt available level as IPPROTO_IP: IP_ADD_MEMBERSHIP: join a multicast group IP_DROP_MEMBERSHIP: leaves a multicast group IP_MULTICAST_IF: Specifies the outgoing multicast datagrams go out Interface IP_MULTICAST_TTL: TTL number IP_MULTICAST_LOOP: whether to ban feedback, my It is understood whether a machine can receive the multicast datagrand Struct ip_mreq of IP_MREQ for IP_ADD_MEMBERSHIP!
Multicast address is 224.0.0.0.1 ~ 239.255.255.255