在python中使用twisted,如何使用多客户端UDP服务器进行语音聊天
当我启动脚本时,服务器只发送回数据一次。有人能帮我吗,或者只是给我一个简单的多客户端UDP服务器的替代方案(也许我自己构建一个更好),我需要在另一个大项目中实现这一点。 提前谢谢在python中使用twisted,如何使用多客户端UDP服务器进行语音聊天,python,sockets,udp,twisted,voice,Python,Sockets,Udp,Twisted,Voice,当我启动脚本时,服务器只发送回数据一次。有人能帮我吗,或者只是给我一个简单的多客户端UDP服务器的替代方案(也许我自己构建一个更好),我需要在另一个大项目中实现这一点。 提前谢谢 服务器: 客户: from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor import pyaudio p = pyaudio.PyAudio() input_stream = p.open
服务器: 客户:
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
import pyaudio
p = pyaudio.PyAudio()
input_stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=44100,
frames_per_buffer=512,
input=True)
stream = p.open(format = pyaudio.paInt16,
channels = 1,
rate = 44100,
output = True)
class MulticastPingClient(DatagramProtocol):
def startProtocol(self):
# Join the multicast address, so we can receive replies:
self.transport.joinGroup("228.0.0.5")
# Send to 228.0.0.5:8005 - all listeners on the multicast address
# (including us) will receive this message.
self.transport.write(input_stream.read(1024), ("228.0.0.5", 8005))
def datagramReceived(self, datagram, address):
stream.write(datagram)
reactor.listenMulticast(8005, MulticastPingClient(), listenMultiple=True)
reactor.run()
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
import pyaudio
p = pyaudio.PyAudio()
input_stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=44100,
frames_per_buffer=512,
input=True)
stream = p.open(format = pyaudio.paInt16,
channels = 1,
rate = 44100,
output = True)
class MulticastPingClient(DatagramProtocol):
def startProtocol(self):
# Join the multicast address, so we can receive replies:
self.transport.joinGroup("228.0.0.5")
# Send to 228.0.0.5:8005 - all listeners on the multicast address
# (including us) will receive this message.
self.transport.write(input_stream.read(1024), ("228.0.0.5", 8005))
def datagramReceived(self, datagram, address):
stream.write(datagram)
reactor.listenMulticast(8005, MulticastPingClient(), listenMultiple=True)
reactor.run()