-
Notifications
You must be signed in to change notification settings - Fork 285
Closed
Labels
Description
When a WebSocket is created using an underlying IPv6 socket, its local_address (and, I assume, the peer address) returns a 4-tuple instead of a 2-tuple.
This means that automatic unpacking of the address into hostname, port throws a ValueError.
Minimal example (using the cherrypy tools)
import cherrypy
from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
from ws4py.websocket import EchoWebSocket
cherrypy.config.update({'server.socket_port': 9000})
cherrypy.config.update({'server.socket_host': "::1"})
WebSocketPlugin(cherrypy.engine).subscribe()
cherrypy.tools.websocket = WebSocketTool()
class Root(object):
@cherrypy.expose
def index(self):
return """<script type="text/javascript">
var sock = new WebSocket("ws://localhost:9000/ws");</script>"""
@cherrypy.expose
def ws(self):
pass
cherrypy.quickstart(Root(), '/', config={'/ws': {'tools.websocket.on': True,
'tools.websocket.handler_cls': EchoWebSocket}})This throws a ValueError when navigating to localhost:9000
The obvious workaround is not using IPv6 addresses in the server deployment.
A fix would be to have WebSocket.local_address and WebSocket.peer_address return the first two elements of the underlying socket's name.