简体   繁体   English

在python中可以在网络中的3台以上计算机之间进行分散式通信吗?

[英]Is decentralized communication between 3+ computers in a network possible in python?

So I've been racking my brain trying to implement a system in which computers on a network (where there are always three or more computers on the network) are able to asynchronously communicate with each other by sending each other data.所以我一直在绞尽脑汁试图实现一个系统,在这个系统中网络上的计算机(网络上总是有三台或更多台计算机)能够通过相互发送数据来相互异步通信。

So far, all I've been able to find as far as solutions go is sockets--which, to my knowledge, requires a client and a server script.到目前为止,就解决方案而言,我所能找到的只是套接字——据我所知,它需要一个客户端和一个服务器脚本。 My first problem is that I'd like to remove any client or server roles since all of the computers on the network are decentralized and running the same script concurrently without a server.我的第一个问题是我想删除任何客户端或服务器角色,因为网络上的所有计算机都是分散的并且在没有服务器的情况下同时运行相同的脚本。 Secondly, all of the computers are sending other nodes (chosen at random) sensor data from a specific point in time.其次,所有计算机都从特定时间点发送其他节点(随机选择)传感器数据。 If, for example, I have 4 computers on the network and--since they're all running the same script--they decide to send their data to another computer at the same time, wouldn't that cause a wait lock since all of the nodes are trying to communicate with another computer, but those computers are unable to accept the connection because they're also trying to send data?例如,如果我在网络上有 4 台计算机并且——因为它们都运行相同的脚本——它们决定同时将数据发送到另一台计算机,这不会导致等待锁定,因为所有的节点正在尝试与另一台计算机通信,但这些计算机无法接受连接,因为它们也在尝试发送数据?

I've considered using multithreading to run my begin_sync and wait_sync functions concurrently, but I'm not sure whether or not that would work.我考虑过使用多线程同时运行我的 begin_sync 和 wait_sync 函数,但我不确定这是否可行。 Does anyone have any suggestions or ideas for solutions that I could look into?有没有人对我可以研究的解决方案有任何建议或想法?

Thanks for your time!谢谢你的时间!

As per NotTheBatman's response, I was able to get this to work using sockets on multiple ports.根据 NotTheBatman 的回应,我能够使用多个端口上的套接字来使其工作。 As far as how I handled being able to wait for sensor data and query other nodes, I simply used multithreading with great success.至于我如何处理能够等待传感器数据和查询其他节点,我只是简单地使用了多线程并取得了巨大的成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM