#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
main()
{
char *send_message ="abcdefg123456";
struct sockaddr_in addr;
int sockLen,sock,j;
char chCmd[500] = {0};//max 500;
char *sou = NULL;
char ch[50]={0};
for(;;)
{
/*******创建套接字******/
sock=socket (AF_INET, SOCK_STREAM, 0);
if (sock == -1)
{
printf ("create sock error\n");
return -1;
}
memset (&addr, 0, sizeof(struct sockaddr_in));
addr.sin_addr.s_addr = inet_addr("192.168.0.18");//服务器IP
addr.sin_family = AF_INET;
addr.sin_port = htons (8080); //端口号
/*******连接服务器********/
if ( connect(sock, (struct sockaddr*)&addr, sizeof(addr)) != -1 )
{
/*********发送信息到服务器********/
if((sockLen=send(sock,send_message,strlen(send_message),0))==-1)
{
printf("send error\n");
goto innererror;
}
while(1)
{
/*********等待接收服务器的数据*********/
if((sockLen=recv(sock,chCmd,sizeof(chCmd),0))>0) //lsq
{
printf("chcmd=%s\n",chCmd);
}
else
{
if (!sockLen)
{
printf("%d client close!\n",sockLen);
goto innererror;//client closed!!!!!!
}
}
}
}
innererror:
close( sock );
printf("error\n");
sleep(5);
}
}
阅读(2679) | 评论(0) | 转发(1) |