Advertisement

linux网络编程学习笔记 第四节:创建UDP通信(双向)(sendto recvfrom inet_aton inet_ntoa inet_addr inet_pton inet_ntop...)

阅读量:

教养超越天性。

Nurture surpasses nature.

UDP协议的双向数据传输与TCP协议在实现方式上存在相似之处,二者均采用多线程机制完成数据的接收与发送。区别在于本次示例代码仅编写了一份程序,若在相同的虚拟机环境中运行,必须确保端口号的不同以避免冲突。

直接展示示例代码

udp_rdwr.c

复制代码
 #include <stdio.h>

    
 #include <sys/types.h>          /* See NOTES */
    
 #include <sys/socket.h>
    
 #include <netinet/in.h>
    
 #include <netinet/ip.h>
    
 #include <arpa/inet.h>
    
 #include <strings.h>
    
 #include <unistd.h>
    
 #include <sys/select.h>
    
 /* According to earlier standards */
    
 #include <sys/time.h>
    
 #include <sys/types.h>
    
 #include <string.h>
    
 #include <s

全部评论 (0)

还没有任何评论哟~