如何在python的simplewebsocketserver中提供IP地址

时间:2019-03-21 09:12:25

标签: python websocket webserver chatterbot

当我运行var ws = new WebSocket("ws://localhost:9000");时,应用程序正在运行,但是当我指定IP地址,即("ws://192.168.3.63:9000")(ws://HOSTNAME:9000)时也没有响应。

from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
from chatbot import get_response ,checkForHyperLinks, convertToHyperLink
import http.server
import socketserver

class ChatServer(WebSocket):

  def handleMessage(self):
      # echo message back to client
      message = self.data
      response = get_response(message)
      self.sendMessage(response)

  def handleConnected(self):
      print(self.address, 'connected')

  def handleClose(self):
      print(self.address, 'closed')

Handler = http.server.SimpleHTTPRequestHandler

Ip="192.168.3.63"
port = 9000


server = SimpleWebSocketServer('',port, ChatServer)
print(server)
server.serveforever()
print("listening",server.serveforever())

0 个答案:

没有答案