I'm having some trouble finding documentation on what the distinction between these settings for the third argument to socket
is. I know about TCP and UDP and their differences and also that IP is one layer up (down?) on the stack... My UDP code seems to work the same whether I set it to IPPROTO_IP
or IPPROTO_UDP
.
相关问题
- Multiple sockets for clients to connect to
- Drakma and Dexador both fails at USocket call whil
- difference between file descriptor and socket file
- Can we create a Silverlight Socket Server ONLY usi
- How do I get the client name from a socket in Java
相关文章
- PostgreSQL field data type for IPv4 addresses
- socket() returns 0 in C client server application
- Passing extra metadata to a RequestHandler using p
- How do I get the external IP of a socket in Python
- Native hooking in Android Client
- Is zeroing out the “sockaddr_in” structure necessa
- Does the TCPServer + BaseRequestHandler in Python&
- Is it possible to convert between Socket and TcpCl
Documentation for
socket()
on Linux is split between various manpages includingip(7)
that specifies that you have to use0
orIPPROTO_UDP
for UDP and0
orIPPROTO_TCP
for TCP. When you use0
, which happens to be the value ofIPPROTO_IP
, UDP is used forSOCK_DGRAM
and TCP is used forSOCK_STREAM
.In my opinion the clean way to create a UDP or a TCP IPv4 socket object is as follows:
The reason is that it is generally better to be explicit than implicit. In this specific case using
0
or worseIPPROTO_IP
for the third argument doesn't gain you anything.Also imagine using a protocol that can do both streams and datagrams like sctp. By always specifying both socktype and protocol you are safe from any ambiguity.