client.c

来自「tiny tcpip on 8051 可以利用在單片機 各種相關應用」· C语言 代码 · 共 56 行

C
56
字号
//  捞 橇肺弊伐篮 Linux 肚绰 Cygwin俊辑 哪颇老窍咯 角青茄促. //弊矾搁 8051苞 捞歹齿阑 烹秦辑 皋矫瘤甫 林绊 罐绰促.#include <sys/types.h>#include <sys/socket.h>#include <stdio.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#define PORT	9999int main(){	int sockfd;	int len;	int i;	char ch;	struct sockaddr_in address; /*AF_INET 档皋牢俊辑 林家绰 sockaddr_in捞扼 阂府绰 备炼眉甫 */					/*荤侩窍咯 疙矫茄促. 捞巴篮 netinet/in.h 俊 沥狼茄促*/	int result;	int cmd;	char buf[1600];    	i = 0;		sockfd = socket( AF_INET, SOCK_STREAM, 0);/*家南阑 积急茄促.*/	address.sin_family = AF_INET;	address.sin_addr.s_addr = inet_addr( "202.30.20.172" );	address.sin_port = htons(PORT);    	len = sizeof(address);	result = connect( sockfd, (struct sockaddr *)&address, len);        	if ( result == -1) {		perror("oops: client1");		exit(1);	}	printf("Connection Established..\n");	while(1) {		i++;		//usleep(100000);		write(sockfd,"I'm CSL..!" ,80);		printf("\t send number : %d \r\n",i);		memset(buf, 0, 512);		len = read(sockfd, buf, 1600);		if (len > 0){	    	printf("%s\r\n",buf);		}      	}		close(sockfd);}

⌨️ 快捷键说明

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