Created
May 3, 2012 00:53
-
-
Save Drvanon/2582275 to your computer and use it in GitHub Desktop.
server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.internet import reactor | |
from twisted.internet.protocol import Protocol, ClientFactory | |
from twisted.protocols import amp | |
class ChangeCurrency(amp.Command): | |
arguments = [('newPrice', amp.Integer())] | |
class MarketProtocol(amp.AMP): | |
def __init__(self, price): | |
self.price = price | |
def connectionMade(self): | |
self.callRemote(ChangePrice, newPrice=price) | |
print 'connection made' | |
def changeCurrency(self): | |
self.factory.currency = price | |
class Factory(ClientFactory): | |
def __init__(self, price): | |
self.price = price | |
self.currency = 0 | |
def buildProtocol(self, addr): | |
return MarketProtocol(self.price) | |
def printCurrency(): | |
print factory.currency | |
def main(price): | |
from twisted.internet import reactor | |
print 'installed' | |
factory = Factory(price) | |
print 'initializing factory' | |
reactor.connectTCP("86.85.138.215", 45000, factory) | |
print 'connecting' | |
reactor.run() | |
print 'reactor done running' | |
if __name__=="__main__":main(10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Traceback (most recent call last): | |
File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithLogger | |
return callWithContext({"system": lp}, func, *args, **kw) | |
File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 69, in callWithContext | |
return context.call({ILogContext: newCtx}, func, *args, **kw) | |
File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext | |
return self.currentContext().callWithContext(ctx, func, *args, **kw) | |
File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext | |
return func(*args,**kw) | |
--- <exception caught here> --- | |
File "/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 591, in _doReadOrWrite | |
why = selectable.doWrite() | |
File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 419, in doConnect | |
self._connectDone() | |
File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 427, in _connectDone | |
self.protocol.makeConnection(self) | |
File "/usr/lib/python2.7/dist-packages/twisted/protocols/amp.py", line 2295, in makeConnection | |
BinaryBoxProtocol.makeConnection(self, transport) | |
File "/usr/lib/python2.7/dist-packages/twisted/protocols/amp.py", line 2042, in makeConnection | |
self.connectionMade() | |
File "client.py", line 13, in connectionMade | |
self.callRemote(ChangePrice, newPrice=price) | |
exceptions.NameError: global name 'ChangePrice' is not defined | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment