本文整理匯總了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)