#include <my_head.h>
#define SER_PORT 8888
#define SER_IP "192.168.31.126"
#define CLI_PORT 6666
#define CLI_IP "192.168.31.106"
int main(int argc, const char *argv[])
{
int sfd = socket(AF_INET, SOCK_STREAM, 0);
if(sfd == -1){
perror("socket error");
return -1;
}
printf("sfd = %d\n",sfd);
struct sockaddr_in cin;
cin.sin_family = AF_INET;
cin.sin_port = htons(CLI_PORT);
cin.sin_addr.s_addr = inet_addr(CLI_IP);
if(bind(sfd, (struct sockaddr*)&cin, sizeof(cin)) == -1){
perror("bind error");
return -1;
}
printf("bind success");
struct sockaddr_in sin;
sin.sin_family = AF_INET;
sin.sin_port = htons(SER_PORT);
sin.sin_addr.s_addr = inet_addr(SER_IP);
if(connect(sfd, (struct sockaddr*)&sin, sizeof(sin)) == -1){
perror("connect error");
return -1;
}
unsigned char rbuf[5]={0xff, 0x02, 0x00, 0x00, 0xff};
unsigned char bbuf[5]={0xff, 0x02, 0x01, 0x00, 0xff};
int i=-50;
int j=103;
while(1){
char ch;
printf("请输入操作代码 W S D A 操作机械臂:\n");
scanf("%c",&ch);
getchar();
printf("%c\n",ch);
switch(ch){
case 'w':
case 'W':
rbuf [3] = ++i;
break;
case 's':
case 'S':
rbuf [3] = --i;
break;
case 'd':
case 'D':
bbuf [3] = ++j;
break;
case 'a':
case 'A':
bbuf [3] = --j;
//printf("texs\n");
break;
default:
printf("按键不符\n");
break;
}
send(sfd, rbuf, sizeof(rbuf), 0);
send(sfd, bbuf, sizeof(bbuf), 0);
}
close(sfd);
return 0;
}