我做了一个程序,允许我每次在unity中按空格键时发送一条消息,并使用cherrpy将其发送到python服务器。在
问题是我的websocket.py'成功地服务于本地主机如下,一旦我启动团结播放器,它只是立即关闭与错误。希望有人帮忙!!在
websocket.pyimport cherrypy
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
from ws4py.websocket import WebSocket
class Root(object):
@cherrypy.expose
def index(self):
return 'some HTML with a websocket javascript connection'
@cherrypy.expose
def ws(self):
# you can access the class instance through
handler = cherrypy.request.ws_handler
class AgentServer(WebSocket):
def opened(self):
print("Opened!")
def closed(self, code, reason):
print("Closed!")
def received_message(self,m):
self.send(m.data,m.is_binary)
if __name__ == "__main__":
cherrypy.config.update({
"server.socket_host": "127.0.0.1",
"server.socket_port": 3000,
})
WebSocketPlugin(cherrypy.engine).subscribe()
cherrypy.tools.websocket = WebSocketTool()
cherrypy.quickstart(Root(), "/", config={
"/ws": {
"tools.websocket.on": True,
"tools.websocket.handler_cls": AgentServer,
}
})
客户端.cs
^{pr2}$
Unity中的错误代码Closed
UnityEngine.Debug:Log(Object)
client:m__3E(Object, CloseEventArgs) (at Assets/client.cs:18)
WebSocketSharp.Ext:Emit(EventHandler`1, Object, CloseEventArgs) (at Assets/Packages/websocket-sharp/Ext.cs:1101)
WebSocketSharp.WebSocket:close(CloseEventArgs, Boolean, Boolean, Boolean) (at Assets/Packages/websocket-sharp/WebSocket.cs:917)
WebSocketSharp.WebSocket:fatal(String, CloseStatusCode) (at Assets/Packages/websocket-sharp/WebSocket.cs:1128)
WebSocketSharp.WebSocket:doHandshake() (at Assets/Packages/websocket-sharp/WebSocket.cs:1085)
WebSocketSharp.WebSocket:connect() (at Assets/Packages/websocket-sharp/WebSocket.cs:958)
WebSocketSharp.WebSocket:Connect() (at Assets/Packages/websocket-sharp/WebSocket.cs:2472)
client:Start() (at Assets/client.cs:20)
Python提示-Pythonwebsocket.py在[03/Oct/2016:22:11:59] ENGINE Listening for SIGTERM.
[03/Oct/2016:22:11:59] ENGINE Bus STARTING
[03/Oct/2016:22:11:59] ENGINE Set handler for console events.
[03/Oct/2016:22:11:59] ENGINE Starting WebSocket processing
[03/Oct/2016:22:11:59] ENGINE Started monitor thread '_TimeoutMonitor'.
[03/Oct/2016:22:11:59] ENGINE Started monitor thread 'Autoreloader'.
[03/Oct/2016:22:11:59] ENGINE Serving on http://127.0.0.1:3000
[03/Oct/2016:22:11:59] ENGINE Bus STARTED
127.0.0.1 - - [03/Oct/2016:22:12:03] "GET / HTTP/1.1" 200 48 "" "websocket-sharp/1.0"