def connectWS(factory, contextFactory=None, timeout=30, bindAddress=None):
 if hasattr(factory, 'reactor'):
  reactor = factory.reactor
 else:
  from twisted.internet import reactor
 if factory.isSecure:
  if (contextFactory is None):
   from twisted.internet import ssl
   contextFactory = ssl.ClientContextFactory()
 if (factory.proxy is not None):
  factory.contextFactory = contextFactory
  conn = reactor.connectTCP(factory.proxy[u'host'], factory.proxy[u'port'], factory, timeout, bindAddress)
 elif factory.isSecure:
  conn = reactor.connectSSL(factory.host, factory.port, factory, contextFactory, timeout, bindAddress)
 else:
  conn = reactor.connectTCP(factory.host, factory.port, factory, timeout, bindAddress)
 return conn

def connectWS ( factory , contextFactory = None , timeout = 30 , bindAddress = None ) : if hasattr ( factory , 'reactor' ) : reactor = factory . reactor else : from twisted . internet import reactor if factory . isSecure : if ( contextFactory is None ) : from twisted . internet import ssl contextFactory = ssl . ClientContextFactory ( ) if ( factory . proxy is not None ) : factory . contextFactory = contextFactory conn = reactor . connectTCP ( factory . proxy [ u'host' ] , factory . proxy [ u'port' ] , factory , timeout , bindAddress ) elif factory . isSecure : conn = reactor . connectSSL ( factory . host , factory . port , factory , contextFactory , timeout , bindAddress ) else : conn = reactor . connectTCP ( factory . host , factory . port , factory , timeout , bindAddress ) return conn
establish websocket connection to a server .