GAWK实用功能与AWK单行命令详解
1. GAWK的网络编程功能
1.1 UDP客户端和服务器
使用UDP协议进行通信的服务器和客户端程序与TCP协议的程序非常相似,唯一的区别是将协议从tcp改为udp。以下是UDP服务器和客户端的代码示例:
-UDP服务器(udpserver.awk):
#UDP-Server BEGIN { print strftime() |& "/inet/udp/8080/0/0" "/inet/udp/8080/0/0" |& getline print $0 close("/inet/udp/8080/0/0") }执行命令:$ awk -f udpserver.awk
-UDP客户端(udpclient.awk):
#UDP-client BEGIN { print "hello from client!" |& "/inet/udp/0/localhost/8080" "/inet/udp/0/localhost/8080" |& getline print $0 close("/inet/udp/0/localhost/8080") }执行命令:$ awk