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

📄 client.c

📁 在89C51上实现TCPIP协议
💻 C
字号:
/* * Copyright (C) 2002 by TechiZ. All rights reserved. * * This program was written in Korean(Comment and some more). * * This program was developed by TechiZ(The Company name). * TechiZ want to share this program with you who loves the 8051 & the TCP/IP. *  * You MUST DOWNLOAD THIS CODE from TechiZ Homepage. * You DO NOT USE THIS CODE FOR COMMERCIAL PURPOSE. * This code is ONLY FREE FOR THE STUDY. * If you want more, send me E-mail. * * E-mail: techiz@techiz.com * ( Subject is : [T89C51RD2 & TinyTCP] bla~ bla bla.... ) * * Homepage: http://www.techiz.com *  * You DO NOT DELETE THIS COPYRIGHT MESSAGE IN THE USING OF THIS CODE. * * In the using of this code, TechiZ does NOT GUARANTEE ABOUT WORKING WITHOUT ERROR. *///  捞 橇肺弊伐篮 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( "210.107.198.178" );	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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -