2011年2月22日
源代码:已经上传至我的资源
服务器端:
#include<sys/socket.h> #include <unistd.h>// for close function #include <string.h> // for bzero function #include<stdio.h> #include<sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include<netinet/in.h> #include <stdlib.h> #define SERV_PORT 5555 #define SERV_IP "xxx.xxx.xxx.xxx"//mx27 board ip #define BACKLOG 10 //the counts of connect can keep in wait queen #define MAXBUFSIZE 200 char buf[MAXBUFSIZE]; //receive buf char str_to_send[200] ="important notice:to cerebrate China log on moon successful on 12nd,Jan,2010. everyone has a day free from work!/n"; int main(int argc, char **argv) { int sockfd,sockfd_client; socklen_t sin_size; // used in accept(),but i don't know what it means printf("#####################################################/n"); printf("socket receive text by pafone 30th,April,2009/n"); printf("server ip:%s port:%d /n",SERV_IP,SERV_PORT); printf("#####################################################/n"); struct sockaddr_in my_addr;//local ip info struct sockaddr_in serv_addr,client_sockaddr; //server ip info int serverport; if(argc == 2) { serverport = atoi(argv[1]); } else { serverport = SERV_PORT; } if(-1 == (sockfd = socket(AF_INET,SO