#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
using namespace std;
#define MAXDATASIZE 16384
#define MASSAGE " 90V20009012046401010008|01#2014032^02#2014034^03#140411077^06#null^07#140804060^08#null"
int main(int argc, char* argv[])
{
int tttfd,tttfd2;//ttt文件描述符
char tttbuf[1204]={0};
tttfd =open("./ttt.txt",O_RDONLY);
tttfd2=read(tttfd,tttbuf,sizeof(tttbuf));
close(tttfd);
printf("The Result =%s\n",tttbuf);
////////////////////////////////////////
cout<<"参数个数"<<argc<<endl;
string server_ip(argv[1]);
string server_port = argv[2];
cout<<"服务器IP "<<server_ip<<endl;
cout<<"服务器监听端口"<<server_port<<endl;
int sockfd, recvbytes;
char buf[MAXDATASIZE];
struct hostent *host;
struct sockaddr_in serv_addr;
if (( sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket error!");
exit(1);
}
bzero(&serv_addr,sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(atoi(argv[2]));
serv_addr.sin_addr.s_addr= inet_addr(argv[1]);
while(1)
{
if (connect(sockfd, (struct sockaddr *)&serv_addr,sizeof(struct sockaddr)) == -1) {
perror("connect error!");
exit(1);
}
//write(sockfd,MASSAGE, sizeof(MASSAGE));
write(sockfd,tttbuf, sizeof(tttbuf));
if ((recvbytes = recv(sockfd, buf, MAXDATASIZE,0)) == -1) {
perror("recv error!");
exit(1);
}
buf[recvbytes] = *\0*;
printf("Received: %s\n",buf);
sleep(20);
}
close(sockfd);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
using namespace std;
#define MAXDATASIZE 16384
#define MASSAGE " 90V20009012046401010008|01#2014032^02#2014034^03#140411077^06#null^07#140804060^08#null"
int main(int argc, char* argv[])
{
int tttfd,tttfd2;//ttt文件描述符
char tttbuf[1204]={0};
tttfd =open("./ttt.txt",O_RDONLY);
tttfd2=read(tttfd,tttbuf,sizeof(tttbuf));
close(tttfd);
printf("The Result =%s\n",tttbuf);
////////////////////////////////////////
cout<<"参数个数"<<argc<<endl;
string server_ip(argv[1]);
string server_port = argv[2];
cout<<"服务器IP "<<server_ip<<endl;
cout<<"服务器监听端口"<<server_port<<endl;
int sockfd, recvbytes;
char buf[MAXDATASIZE];
struct hostent *host;
struct sockaddr_in serv_addr;
if (( sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket error!");
exit(1);
}
bzero(&serv_addr,sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(atoi(argv[2]));
serv_addr.sin_addr.s_addr= inet_addr(argv[1]);
while(1)
{
if (connect(sockfd, (struct sockaddr *)&serv_addr,sizeof(struct sockaddr)) == -1) {
perror("connect error!");
exit(1);
}
//write(sockfd,MASSAGE, sizeof(MASSAGE));
write(sockfd,tttbuf, sizeof(tttbuf));
if ((recvbytes = recv(sockfd, buf, MAXDATASIZE,0)) == -1) {
perror("recv error!");
exit(1);
}
buf[recvbytes] = *\0*;
printf("Received: %s\n",buf);
sleep(20);
}
close(sockfd);
return 0;
}