⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client2.c

📁 socket通信的源代码。可以直接用GCC编译.
💻 C
字号:
/* client process, passed  */#include <ctype.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <stdio.h>#include <stdlib.h>#define SIZE sizeof(struct sockaddr_in)main(){  int sockfd; char c, rc;  struct   sockaddr_in server={AF_INET,7000};/*   (1) convert and store server's IP address  */  server.sin_addr.s_addr=inet_addr("127.0.0.1");/*   (2) setup the transport end point  */  if ((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)  {    printf("bind--sock call error\n");    exit(1);  }/*   (3) connect the socket to the server's address */  if (connect(sockfd,(struct sockaddr *)&server, SIZE)==-1)  {    printf("connect --sock call error\n");    exit(1);  }/*  send and receive info with the server */	while(1){      printf("\ninput a lower case char\n");      c=getchar();	  getchar();	  if (c=='0') { printf("flag is appear,now exit\n"); break;}      send(sockfd,&c,1,0);      if (recv(sockfd,&c,1,0)>0)   	  //printf("%c",c);	  putchar(c);	}      close(sockfd); 	  exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -