This section explains the meaning of all the other fields, as well as the range of values and the defaults. All of the fields are mandatory. To let the system pick a value, or if the field doesn't apply to the protocol, specify it as `0':
Experts in network programming will notice that the usual client/server asymmetry found at the level of the socket API is not visible here. This is for the sake of simplicity of the high-level concept. If this asymmetry is necessary for your application, use another language. For gawk, it is more important to enable users to write a client program with a minimum of code. What happens when first accessing a network connection is seen in the following pseudocode:
if ((name of remote host given) && (other side accepts connection)) { rendez-vous successful; transmit with getline or print } else { if ((other side did not accept) && (localport == 0)) exit unsuccessful if (TCP) { set up a server accepting connections this means waiting for the client on the other side to connect } else ready }
The exact behavior of this algorithm depends on the values of the fields of the special file name. When in doubt, table-inet-components gives you the combinations of values and their meaning. If this table is too complicated, focus on the three lines printed in bold. All the examples in Networking With gawk, use only the patterns printed in bold letters.
protocol | local port | host name | remote port | Resulting connection-level behavior
|
---|---|---|---|---|
tcp | 0 | x | x |
Dedicated client, fails if immediately connecting to a
server on the other side fails
|
udp | 0 | x | x | Dedicated client
|
raw | 0 | x | 0 | Dedicated client, works only as root
|
tcp, udp | x | x | x |
Client, switches to dedicated server if necessary
|
tcp, udp | x | 0 | 0 |
Dedicated server
|
raw | 0 | 0 | 0 | Dedicated server, works only as root
|
tcp, udp, raw | x | x | 0 | Invalid
|
tcp, udp, raw | 0 | 0 | x | Invalid
|
tcp, udp, raw | x | 0 | x | Invalid
|
tcp, udp | 0 | 0 | 0 | Invalid
|
tcp, udp | 0 | x | 0 | Invalid
|
raw | x | 0 | 0 | Invalid
|
raw | 0 | x | x | Invalid
|
raw | x | x | x | Invalid
|
Table 2.1: /inet Special File Components
In general, TCP is the preferred mechanism to use. It is the simplest protocol to understand and to use. Use the others only if circumstances demand low-overhead.