通过互联网传输数据的最简单方法,Python
我有两台电脑,都连接到互联网。我想在它们之间传输一些基本数据(字符串、整数、浮点数)。我是网络新手,所以我正在寻找最简单的方法来做到这一点。我需要哪些模块来做到这一点?
两个系统都运行 Windows 7。
I have two computers, both are connected to the internet. I'd like transfer some basic data between them (strings, ints, floats). I'm new to networking so I'm looking for the most simple way to do this. What modules would I be looking at to do this?
Both systems would be running Windows 7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只要它不是异步的(同时发送和接收),您就可以使用套接字接口。
如果您喜欢抽象(或需要异步支持),总有 Twisted。
这是一个套接字接口的示例(随着程序变大,它会变得更难使用,所以,我建议使用 Twisted 或 asyncore< /a>)
python 文档非常好,我从那里选择了 mysend() 函数。
如果你正在做计算相关的工作,请查看 XML-RPC,Python 拥有这一切给你打包好了。
请记住,套接字就像文件一样,因此编写代码并没有太大区别,因此,只要您可以执行基本的文件 io 并理解事件,套接字编程一点也不难(只要你不会像复用 VoIP 流那样变得太复杂......)
As long as its not asynchronous (doing sending and receiving at once), you can use the socket interface.
If you like abstractions (or need asynchronous support), there is always Twisted.
Here is an example with the socket interface (which will become harder to use as your program grows larger, so, I would suggest either Twisted or asyncore)
The python documentation is excellent, I picked up the mysend() function from there.
If you are doing computation related work, check out XML-RPC, which python has all nicely packaged up for you.
Remember, sockets are just like files, so they're not really much different to write code for, so, as long as you can do basic file io, and understand events, socket programming isn't hard, at all (as long as you don't get too complicated like multiplexing VoIP streams...)
如果你完全不知道socket是什么,那么使用Twisted可能会有点困难。由于您需要识别正在传输的数据的类型,事情会变得更加困难。
因此也许ICE,互联网通信引擎的Python版本会更适合,因为它隐藏了一个网络编程的许多肮脏细节。看看你好世界看看它是否能完成你的工作。
If you have completely no idea of what socket is, it might be a bit difficult to use Twisted. And as you need to identify the type of the data being transferred, things will be harder.
So perhaps the python version of ICE, the Internet Communication Engine will be more suitable for because it hides a lot of dirty details of network programming. Have a look of the hello world to see if it does your work.
看这里:
如果您(正如我认为的那样)尝试使用套接字,这就是您正在寻找的:https://docs.python.org/2/howto/sockets.html
我希望这会有所帮助,因为它对我来说效果很好。
或者添加此类以实现持续连接:
Look here:
If you ,as I think you are, trying to use sockets this is what you are looking for:https://docs.python.org/2/howto/sockets.html
I hope this will help as it worked well for me.
or add this class for constant connection: