1.并发服务器与客户端 (UDP)
1 //client.c 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 #include <unistd.h> 6 #include <netinet/in.h> 7 #include <fcntl.h> 8 9 #define MAX 10 10 #define MAXLINE 18 11 #define SERV_PORT 8000 12 13 int main(int argc, char *argv[]) 14 { 15 struct sockaddr_in servaddr; 16 int sockfd = 0, n = 0, number = 0; 17 char buf[MAXLINE] = {0}; 18 char str[INET_ADDRSTRLEN] = {0}; 19 char find[MAXLINE] = {0}; 20 socklen_t servaddr_len; 21 int len = 0, fr = 0, fw = 0, data_len = 0, read_len = 0; 22 23 sockfd = socket(AF_INET, SOCK_DGRAM, 0); 24 25 bzero(&servaddr, sizeof(servaddr)); 26 servaddr.sin_family = AF_INET; 27 inet_pton(AF_INET, argv[1], &servaddr.sin_addr); 28 servaddr.sin_port = htons(SERV_PORT); 29 30 while((fgets(buf, MAXLINE, stdin) != NULL)) 31 { 32 if(' ' == buf[strlen(buf) - 1]) { 33 buf[strlen(buf) - 1] = '