Changeset 45 for tabled.tac

Show
Ignore:
Timestamp:
02/08/08 19:24:35 (4 years ago)
Author:
mike
Message:

Got ucommet working

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tabled.tac

    r43 r45  
    11""" 
    22""" 
    3 import sys 
    4 from random import randint 
    53from holdemtable import holdemtable 
    64import protocol 
    7 import getopt 
    8 #import cjson 
    95import simplejson 
    106from twisted.internet.protocol import Factory 
    11 from twisted.internet import reactor 
    127from twisted.protocols.basic import NetstringReceiver 
    138from twisted.internet import defer 
    14 from twisted.application import internet, service, strports 
    15 from twisted.web2 import http, resource, channel, stream, server, static, http_headers, responsecode 
     9from twisted.application import internet, service 
     10from twisted.web2 import http, resource, channel, server, static 
    1611from path import path 
    17 import cometd 
    18  
    19  
    20 encodejson = simplejson.dumps 
    21 decodejson = simplejson.loads 
     12import ucomet 
     13from ucomet import encodejson,decodejson 
     14 
     15 
    2216tables = {} 
    2317class BasePokerTableHandler: 
     
    8579clientChannels = [ r"\/poker" ] 
    8680 
    87 class PokerSubscription(cometd.ClientSubscription,BasePokerTableHandler): 
    88     def __init__(self, channel): 
     81class PokerSubscription(ucomet.ClientSubscription, BasePokerTableHandler): 
     82    def __init__(self, channel, sendMessageCallback): 
    8983        BasePokerTableHandler.__init__(self) 
    90         cometd.ClientSubscription.__init__(self, channel) 
     84        ucomet.ClientSubscription.__init__(self, channel, sendMessageCallback) 
    9185 
    9286    def messageReceived(self,message): 
     
    9589    def sendMessageViaTransport(self,data): 
    9690        self.sendMessage(data) 
    97  
    98 class WebClient(cometd.Client): 
    99      
    100     def generateSubscription(self, channel): 
    101         return PokerSubscription( channel ) 
    102  
    103     def subscribe(self, channel): 
    104         #we only want poker channels 
    105         print "SUB ---------------- CHAN " + channel 
    106         if channel == "/poker": 
    107             return cometd.Client.subscribe(self,channel) 
    108         else: return False 
    109  
    11091 
    11192 
     
    194175 
    195176""" 
    196 #cometd.verbose = False 
    197177class CometdRunner(resource.Resource): 
    198     # blah, hacky class. Wish we didn't need it 
    199178    addSlash = True 
    200179    child_web = static.File(path("web").abspath()) 
    201     child_cometd = cometd.cometd() 
    202     child_cometd.ClientType = WebClient 
    203     #child_cometd 
     180    child_cometd = ucomet.ucomet() 
     181#    child_cometd.ClientType = WebClient 
     182    child_cometd.ClientSubscriptionType = PokerSubscription 
    204183    def render(self, ctx): 
    205184        return http.Response( stream="hi") 
     
    227206print "Listening on localhost:%d(tcp) %d(http)" % (port, port2) 
    228207 
    229 # vim:filetype=python 
     208