用于将 1 字节字符发送到 IP 地址的按钮
我是Python新手,我正在寻找一种将1字节字符(例如:字母“D”)发送到IP地址的方法。这是用来控制机器人的,所以我只需要前进、后退、向左和向右。我在网上做了一些研究,它建议使用套接字连接到 IP 地址,但这对我来说似乎有点令人困惑。我已经在我的网页中制作了4个按钮,但我不太确定如何让网页在用户单击按钮时向IP地址发送信号(例如:如果用户按“右”按钮,网页将发送一个单字节字符“r”到IP地址)
任何帮助将不胜感激
ps我使用的网络方法之间有什么大的区别吗?就像wifi和3G之间
I am new to python and I am looking for a way to send a 1 byte character (for example: the letter "D") to an ip address. This is used to control a robot so all I need are forward, backward, left and right. I've done some research online and it suggests using sockets to connect to the ip address but it seems kind of confusing to me. I have made 4 buttons in my webpage already but I am not too sure on how to make the webpage send out the signal to the ip address when the user click on the button (for example: if the user press the "right" button, the webpage will send a one byte character "r" to the ip address)
Any help would be greatly appreciated
ps would there be any big difference between the networking method i use? like between wifi and 3G
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
套接字很简单,尤其是在 Python 中! :)
这是一个简单的程序,用于向某个 IP 地址发送一封信:
机器人当然需要一个类似的程序来接收命令:
正如您所看到的,需要编写和理解的代码非常少。您实际上不必了解网络和 TCP/IP 的大部分工作原理,只需了解套接字用于通过 Internet 进行通信即可。 :)
复制第一个程序,每个按钮一个,并修改发送到服务器的内容。然后你有四个程序发送不同的命令,连接到你的按钮。
了解有关 Python 套接字的更多信息此处和此处。
Sockets are easy, especially in Python! :)
This is a simple program to send a single letter to some ip-address:
The robot of course needs a similar program to receive commands:
As you can see, there is very little code to write and understand. You don'r really have to understand most of how networking and TCP/IP works, just that a socket is used to communicate over the Internet. :)
Duplicate the first program, one for each button, and modify what is sent to the server. Then you have four programs sending different commands, to be connected to your buttons.
Read more on Python sockets here, and here.