如何在C语言Windows上通过Internet发送数据
我对套接字编程和 C 语言非常陌生。我想通过互联网远程操作机器人,因为我必须向机器人计算机发送一些值。这是我的代码...
x = state.position_val[0];
y = state.position_val[1];
z = state.position_val[2];
Rx = state.gimbal_joints[0]*1000;
Ry= state.gimbal_joints[1]*1000;
Rz = state.gimbal_joints[2]*1000;
double arr[7] = { x, y, z, Rx, Ry, Rz, btonn };
SAFEARRAY* psa = SafeArrayCreateVector(VT_R8, 0, 7);
void* data;
SafeArrayAccessData(psa, &data);
CopyMemory(data, arr, sizeof(arr));
SafeArrayUnaccessData(psa);
return psa;
这些是每次循环的 while 循环下的代码片段,此代码获取机器人的状态值并创建一个进一步用于远程操作的数组。我需要通过互联网将该数组发送到另一台计算机。 请帮助我该怎么做?
I am pretty new to socket programming and the C language. I want to teleoperate a robot over the internet for that I have to send some values to a robot computer. Here is my code...
x = state.position_val[0];
y = state.position_val[1];
z = state.position_val[2];
Rx = state.gimbal_joints[0]*1000;
Ry= state.gimbal_joints[1]*1000;
Rz = state.gimbal_joints[2]*1000;
double arr[7] = { x, y, z, Rx, Ry, Rz, btonn };
SAFEARRAY* psa = SafeArrayCreateVector(VT_R8, 0, 7);
void* data;
SafeArrayAccessData(psa, &data);
CopyMemory(data, arr, sizeof(arr));
SafeArrayUnaccessData(psa);
return psa;
These are the code snippets under the while loop at each loop this code gets the state value of the robot and creates an array that is further used for teleoperation. I need to send this array over the internet to another computer.
Please help me how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经在 Windows 计算机上对此进行了测试
转发 tcp://3.tcp.ngrok.io:15842 ->本地主机:80
这里ngrok将把本地端口分配给80,并将随机端口分配给外部网络,即内部暴露端口。您必须将 80 和该端口添加到机器人网络设备的防火墙规则中)。
转到 https://whatismyipaddress.com/hostname-ip 此处放置3。 tcp.ngrok.io 从 ngrok 控制台查看 IP 地址框。您将获得您的机器人的全球IP。您可以从世界任何地方连接到您的机器人。
以下是您可以编译和运行的客户端和服务器示例。
Client.c
Server.c
您现在可以在机器人和计算机之间发送接收数据
I have tested this on Windows machine
Forwarding tcp://3.tcp.ngrok.io:15842 -> localhost:80
Here ngrok will assign a local PORT to 80 and random port to outside network ie Interner exposed port. You have to add 80 and that port to your firewall rules of robot network device).
Goto https://whatismyipaddress.com/hostname-ip here put 3.tcp.ngrok.io Look IP address box from ngrok console out. You will get your robot's global IP. that you can connect to your robot from anywhere in the world.
Following are the Client and Server examples that you can compile and run.
Client.c
Server.c
You can now send receive data between robot and your computer