#include<myhd.h>
#define CLIPORT 8888
#define CLIIP "192.168.115.232"
int main(int argc, const char *argv[])
{
//创建客户端套接字
int cfd=socket(AF_INET,SOCK_STREAM,0);
if(cfd==-1)
{
perror("socket perror");
return -1;
}
printf("cfd=%d\n",cfd);
//绑定服务器(可选)
//进行连接服务器
//1、填充地址信息结构
struct sockaddr_in sin;
sin.sin_family=AF_INET;
sin.sin_port=htons(CLIPORT);
sin.sin_addr.s_addr=inet_addr(CLIIP);
if(connect(cfd,(struct sockaddr*)&sin,sizeof(sin))==-1)
{
perror("connect error");
return -1;
}
printf("connect success\n");
//进行通信
char x;
char rbuf[5]={0xff,0x02,0x00,0x00,0xff};
char bbuf[5]={0xff,0x02,0x01,0x00,0xff};
send(cfd,rbuf,sizeof(rbuf),0);
send(cfd,bbuf,sizeof(bbuf),0);
char key;
while(1)
{
printf("please enter key\n");
key=getchar();
getchar();
switch(key)
{
case 'w':
{
printf("红色臂角度将增大\n");
rbuf[3]=rbuf[3]+2;
/* if(rbuf[3]>90)
{
rbuf[3]=90;
continue;
}*/
send(cfd,rbuf,sizeof(rbuf),0);
}
break;
case 's':
{
printf("红色臂角度将减小\n");
rbuf[3]=rbuf[3]-2;
send(cfd,rbuf,sizeof(rbuf),0);
}
break;
case 'd':
{
printf("蓝色臂角度将增大\n" );
bbuf[3]=bbuf[3]+2;
send(cfd,bbuf,sizeof(bbuf),0);
}
break;
case 'a':
{
printf("蓝色臂角度将减小\n");
bbuf[3]=bbuf[3]-2;
send(cfd,bbuf,sizeof(bbuf),0);
}
break;
default:
break;
}
}
//关闭客户端套接字
close(cfd);
return 0;
}