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 天前
Java网络编程:(socket API编程:TCP协议的 socket API -- 回显程序的服务器端程序的编写)
java·网络·tcp/ip
FPGA_Linuxer3 天前
FPGA 40 DAC线缆和光模块带光纤实现40G UDP差异
网络协议·fpga开发·udp
real 13 天前
传输层协议UDP
网络·网络协议·udp
路由侠内网穿透3 天前
本地部署 GPS 跟踪系统 Traccar 并实现外部访问
运维·服务器·网络·windows·tcp/ip
酷飞飞3 天前
Python网络与多任务编程:TCP/UDP实战指南
网络·python·tcp/ip
hsjkdhs3 天前
网络编程之UDP广播与粘包问题
网络·网络协议·udp
yzx9910133 天前
接口协议全解析:从HTTP到gRPC,如何选择适合你的通信方案?
网络·人工智能·网络协议·flask·pygame
风_峰3 天前
【ZYNQ开发篇】Petalinux和电脑端的静态ip地址配置
网络·嵌入式硬件·tcp/ip·ubuntu·fpga开发
板鸭〈小号〉3 天前
UDP-Server(3)chat聊天室
网络·网络协议·udp
weixin_456904273 天前
使用HTTPS 服务在浏览器端使用摄像头的方式解析
网络协议·http·https