Advertisement

c语言网络通信客户端/服务器(UDP)

阅读量:

客户端

复制代码
 #include <stdio.h>

    
 #include <sys/socket.h>
    
 #include <netinet/in.h> //读写分离就要包含线程相关的头文件
    
 #include <stdlib.h>
    
 #include <string.h>
    
 #include <arpa/inet.h>
    
 #include <unistd.h>
    
  
    
 #define SERVPORT 5000
    
  
    
 int main(int argc, char **argv)
    
 {
    
     int ud, n;
    
     struct sockaddr_in ser, cli;
    
     char sendline[1000];
    
     char recvline[1000];
    
  
    
     if (argc != 2)
    
     {
    
     printf("usage: server address!\n");
    
     exit(0);
    
     }
    
  
    
     ud = socket(AF_INET, SOCK_DGRAM,

全部评论 (0)

还没有任何评论哟~