在antd Form表單中select設定初始值操作
阿新 • • 發佈:2020-11-03
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <errno.h> 5 #include <sys/socket.h> 6 #include <sys/types.h> 7 #include <netinet/in.h> 8 #include <unistd.h> 9 #include <arpa/inet.h> 10 int main() 11 { 12 printf("a server\n"); 13 int listenfd = socket(AF_INET, SOCK_STREAM, 0);//建立一個socket描述符,唯一標識一個socket,socket()返回檔案描述符\ 14 0,1,2分別表示標準輸入、標準輸出、標準錯誤,所以其他開啟的檔案描述符都會大於2, 錯誤時就返回 -1 15 if(listenfd == -1) 16 { 17 printf("error:socket\n"); 18 return 0; 19 } 20 21 struct sockaddr_in addr;22 addr.sin_family = AF_INET;//IPV4 23 addr.sin_port = htons(8000);//host to net,主機位元組轉為網路位元組 24 addr.sin_addr.s_addr = INADDR_ANY;//指定ip地址:所有地址 25 if(bind(listenfd, (struct sockaddr*)&addr, sizeof(addr)) == -1)//bind()把地址和埠號組合賦給socket 26 { 27 printf("error:bind()\n"); 28 return0; 29 } 30 31 if(listen(listenfd, 5) == -1)//int listen( int sockfd/*用於標識一個已捆綁未連線套介面的描述字*/,\ 32 int backlog/*等待連線佇列最大長度*/); 33 { 34 printf("error:listen\n"); 35 return 0; 36 } 37 38 int conn;//客戶端套接字描述字 39 char clientIP[INET_ADDRSTRLEN]; 40 struct sockaddr_in clientAddr; 41 socklen_t clientAddrLen = sizeof(clientAddr); 42 while(1) 43 { 44 printf("listening......\n"); 45 conn = accept(listenfd, (struct sockaddr*)&clientAddr, &clientAddrLen);//監聽到之後,呼叫accept() 46 if(conn < 0) 47 { 48 printf("error:accept\n"); 49 continue; 50 } 51 inet_ntop(AF_INET/*IPV4*/, &clientAddr.sin_addr/*source*/, clientIP/*destination*/, INET_ADDRSTRLEN/*IP長度*/); 52 /*在點分十進位制和二進位制整數轉換*/ 53 printf("connect %s\n",clientIP);//IP:port 54 55 char buff[255]; 56 while(1) 57 { 58 for(int i=0; i<255; ++i)buff[i]=0; 59 int len = recv(conn, buff/*存放接收資料*/, sizeof(buff), 0/*一般置零*/); 60 buff[len] = '\0'; 61 if(!strcmp(buff,"exit")) 62 { 63 printf("disconnect\n"); 64 return 0; 65 } 66 printf("%s\n",buff); 67 for(int i=0; i<len; ++i) 68 { 69 buff[i] = toupper(buff[i]); 70 } 71 send(conn, buff, len, 0); 72 } 73 close(conn/*socket描述字*/);//關閉連線 74 } 75 close(listenfd); 76 return 0; 77 }
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <errno.h> 5 #include <sys/socket.h> 6 #include <sys/types.h> 7 #include <netinet/in.h> 8 #include <unistd.h> 9 #include <arpa/inet.h> 10 int main() 11 { 12 printf("a client\n"); 13 // socket 14 int client = socket(AF_INET, SOCK_STREAM, 0); 15 if (client == -1) 16 { 17 printf("error:socket\n"); 18 return 0; 19 } 20 // connect 21 struct sockaddr_in serverAddr; 22 serverAddr.sin_family = AF_INET; 23 serverAddr.sin_port = htons(8000); 24 serverAddr.sin_addr.s_addr = inet_addr("192.168.246.140");//連線到master 25 if (connect(client, (struct sockaddr*)&serverAddr, sizeof(serverAddr)) < 0) 26 { 27 printf("error:connect"); 28 return 0; 29 } 30 printf("connect\n"); 31 char data[255]; 32 char result[255]; 33 while (1) 34 { 35 scanf("%s",data); 36 if(!strcmp(data,"exit")) 37 { 38 printf("disconnect"); 39 break; 40 } 41 send(client, data, strlen(data), 0); 42 for(int i=0 ;i<sizeof(result);++i)result[i]=0; 43 int len = recv(client, result, sizeof(result), 0); 44 printf("result:%s\n",result); 45 } 46 close(client); 47 return 0; 48 }