[英]How could i repeatedly send messages through server socket in python?
Like the title, i would like to know how to send messages repeatedly. 像标题一样,我想知道如何重复发送消息。
Is it as simple as using a "while" function? 它像使用“ while”函数一样简单吗?
What I'm trying to do is, when ever a client joins. 我想做的是,无论何时有客户加入。 I would like to have the server end, constantly send the data to the client.
我想要服务器端,不断将数据发送到客户端。 And if possible a way to adjust how soon i want the next message sent out.
如果可能的话,可以调整我要多久发送下一条消息。
Any help would be appreciated, thanks. 任何帮助,将不胜感激,谢谢。
Read about the SocketServer module, in particular the ThreadingMixIn to allow you to handle multiple clients simultaneously. 阅读有关SocketServer模块的信息,尤其是ThreadingMixIn,以允许您同时处理多个客户端。 It is a Python library, and the SocketServer.py source file can be read to see how it is implemented.
它是一个Python库,可以读取SocketServer.py源文件以了解其实现方式。
import socket, using socket.socket If that helps any.
使用socket.socket导入套接字,如果有帮助的话。 I figured out how to repeatedly send the data.
我想出了如何重复发送数据。 Thing is now, is that, i need to know how to break from the loop.
现在,我需要知道如何摆脱循环。 when ever a new client joins the server - Shane O
每当新客户端加入服务器时-Shane O
Instead of doing 而不是做
while True:
Do 做
inloop = True;
while inloop:
bla
if(something):
inloop = false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.