本文整理汇总了Python中protocol.Protocol.connectionMade方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.connectionMade方法的具体用法?Python Protocol.connectionMade怎么用?Python Protocol.connectionMade使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.connectionMade方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _perform_request
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import connectionMade [as 别名]
def _perform_request(self, _, request, session):
request.setHeader('content-type', 'application/stratum')
request.setHeader('server', settings.USER_AGENT)
request.setHeader('x-session-timeout', session.sessionTimeout)
request.setHeader('access-control-allow-origin', '*') # Allow access from any other domain
# Update client's IP address
session.transport.peer = request.getHost()
# Although it isn't intuitive at all, request.getHeader reads request headers,
# but request.setHeader (few lines above) writes response headers...
if 'application/stratum' not in request.getHeader('content-type'):
session.transport.write("%s\n" % json.dumps({'id': None, 'result': None, 'error': (-1, "Content-type must be 'application/stratum'. See http://stratum.bitcoin.cz for more info.", "")}))
self._finish(None, request, session.transport, session.lock)
return
if not session.protocol:
# Build a "protocol connection"
proto = Protocol()
proto.transport = session.transport
proto.factory = self
proto.connectionMade()
session.protocol = proto
else:
proto = session.protocol
# Update callback URL if presented
callback_url = request.getHeader('x-callback-url')
if callback_url != None:
if callback_url == '':
# Blank value of callback URL switches HTTP Push back to HTTP Poll
session.transport.push_url = None
else:
session.transport.push_url = callback_url
data = request.content.read()
if data:
counter = RequestCounter()
counter.on_finish.addCallback(self._finish, request, session.transport, session.lock)
proto.dataReceived(data, request_counter=counter)
else:
# Ping message (empty request) of HTTP Polling
self._finish(None, request, session.transport, session.lock)
示例2: connectionMade
# 需要导入模块: from protocol import Protocol [as 别名]
# 或者: from protocol.Protocol import connectionMade [as 别名]
def connectionMade(self):
WebSocketServerProtocol.connectionMade(self)
Protocol.connectionMade(self)