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;
}

按下后机械臂反应

相关推荐
张人玉21 小时前
C# TCP 服务器和客户端
服务器·tcp/ip·c#
雯0609~21 小时前
宝塔配置:IP文件配置,根据端口配置多个项目文件(不配置域名的情况)
服务器·网络协议·tcp/ip
沧澜sincerely21 小时前
运输层协议概述及UDP
网络·udp·运输层
稚辉君.MCA_P8_Java1 天前
深入理解 TCP;场景复现,掌握鲜为人知的细节
java·linux·网络·tcp/ip·kubernetes
小无名呀1 天前
socket_udp
linux·网络·c++·网络协议·计算机网络·udp
_Johnny_1 天前
Ubuntu 配置临时 IP 和 VLAN
tcp/ip·ubuntu·php
憧憬成为原神糕手1 天前
传输层协议 TCP 三次握手/四次挥手 TIME_WAIT
网络·tcp/ip·安全
花阴偷移1 天前
逆向基础--汇编基础(CS与IP) (05)
网络·汇编·网络协议·tcp/ip
天玺-vains1 天前
借助Github Action实现通过 HTTP 请求触发邮件通知
网络协议·http·github
ZhengEnCi1 天前
N2G-为什么90%的人不会计算子网掩码?大厂网络工程师的CIDR与子网掩码完全解析
网络协议