day2:TCP、UDP网络通信模型

思维导图

机械臂实现

#include <head.h>
#define SER_POTR 8899
#define SER_IP "192.168.125.223"
int main(int argc, const char *argv[])
{
	//创建套接字
	int cfd=socket(AF_INET,SOCK_STREAM,0);
	if(cfd==-1)
	{
		perror("");
		return -1;
	}
	//链接
	struct sockaddr_in sin;
	sin.sin_family=AF_INET;
	sin.sin_port=htons(SER_POTR);
	sin.sin_addr.s_addr=inet_addr(SER_IP);
	if(connect(cfd,(struct sockaddr*)&sin,sizeof(sin))==-1)
	{
		perror("connect error:");
		return -1;
	}
	char red[5]={0xff,0x02,0x00,0x00,0xff};
	unsigned char blue[5]={0xff,0x02,0x01,0x8a,0xff};
	while(1)
	{
		char cmd;
		printf("请输入命令:");
		scanf("%c",&cmd);
		getchar();
		switch(cmd)
		{
		case 'w':
			{

				red[3]+=10;
				send(cfd,red,sizeof(red),0);
				break;
			}
		case 's':
			{

				red[3]-=10;
				send(cfd,red,sizeof(red),0);
				break;
			}
		case 'a':
			{

				blue[3]-=10;
				send(cfd,blue,sizeof(blue),0);
				break;
			}
		case 'd':
			{

				blue[3]+=10;
				send(cfd,blue,sizeof(blue),0);

				break;
			}
		default:
			{
				printf("输入有误\n");
			}

		}
	}



	return 0;
}

按下后机械臂反应

相关推荐
查理养殖场2 小时前
计算机网络之TCP的可靠传输
网络·tcp/ip·计算机网络
六六六六六66662 小时前
企业组网IP规划与先关协议分析
服务器·网络·tcp/ip
AIGC安琪3 小时前
【Stable Diffusion】SD迎来动画革命,AnimateDiff快速出图
人工智能·网络协议·tcp/ip·stable diffusion·aigc
渔舟唱晚@4 小时前
FFmpeg+WebSocket+JsMpeg实时视频流实现方案
websocket·网络协议·ffmpeg
荔枝荷包蛋66613 小时前
【Linux】HTTP:Cookie 和 Session 详解
网络·网络协议·http
遥遥远方 近在咫尺13 小时前
HTTPS原理
网络协议·https
编程星空14 小时前
HTTP 和 HTTPS 的区别
网络协议·http·https
我们的五年16 小时前
【Linux网络】TCP/IP地址的有机结合(有能力VS100%???),IP地址的介绍
linux·运维·网络·tcp/ip
qq_3927944817 小时前
深入解析:短轮询、长轮询、长连接与WebSocket(原理到实现)
网络·websocket·网络协议
忆源18 小时前
SOME/IP--协议英文原文讲解11
网络·网络协议·tcp/ip