简体   繁体   English

我如何通过python的服务器套接字反复发送消息?

[英]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.

相关问题 我如何在 python 套接字中更快地发送大消息? - How i send big messages faster in python socket? 如何通过python中的套接字将字符串发送到java服务器? - How to send a string through a socket in python to a java server? 如何在服务器套接字上发送和接收消息? - How to send and receive messages on a server socket? 我们如何通过套接字编程(Python)与不同网络上的服务器和客户端建立服务器和客户端之间的连接? - How could we establish connection between server and client through socket programming(Python) with server and client on different networks? 如何使我的Flask服务器通过flask socket-IO向特定客户端发出消息 - How can I make my flask server emit messages through flask socket-IO to specific client Java Server SSL套接字和Python Client SSL套接字-服务器发送消息时出现问题 - Java Server SSL Socket and Python Client SSL socket - problems when server send messages 如何使用python socket模块向远程计算机发送消息? - How to send messages to a remote computer using python socket module? Python / Socket:如何在不等待响应的情况下发送多条消息? - Python/Socket: How to send multi messages without waiting the respond? 如何使用 python 客户端和 C 服务器通过套接字正确发送图像 - How to correctly send image through socket using python client and C server 如何将 RabbitMQ 队列连接到 Socket IO 服务器并同时从 Socket IO 服务器向客户端发送消息 - How to connect RabbitMQ Queue into Socket IO server and send messages from Socket IO server to client concurrently
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM