Ошибка: «Не удалось прослушать 192.168.0.3:9090: [WinError 10049] Запрошенный адрес недопустим в # его контексте.»
порты с сервера и маршрутизатора открыты для TCP и брандмауэр и антивирус отключены
import sys
if 'twisted.internet.reactor' in sys.modules:
del sys.modules['twisted.internet.reactor']
from kivy.support import install_twisted_reactor
install_twisted_reactor()
from twisted.internet import reactor
from twisted.internet import protocol
class EchoServer(protocol.Protocol):
def __init__(self, factory):
self.factory = factory
def connectionMade(self):
self.factory.clients.append(self)
def dataReceived(self, data):
response = self.factory.app.handle_message(data)
for client in self.factory.clients:
if response:
client.transport.write(response)
def connectionLost(self, reason):
self.factory.clients.remove(self)
class EchoServerFactory(protocol.Factory):
protocol = EchoServer
def __init__(self, app):
self.app = app
self.clients = []
def buildProtocol(self, addr):
return EchoServer(self)
from kivy.app import App
from kivy.uix.label import Label
class TwistedServerApp(App):
label = None
def build(self):
self.label = Label(text="server started\n")
# this works, but when I changed interface='192.168.0.3' it gives an error of invalid IP in its context
reactor.listenTCP(9090, EchoServerFactory(self), interface='localhost')
return self.label
def handle_message(self, msg):
msg = msg.decode('utf-8')
self.label.text = "received: {}\n".format(msg)
self.label.text += "responded: {}\n".format(msg)
return msg.encode('utf-8')
if __name__ == '__main__':
TwistedServerApp().run()