#!/usr/bin/env python
# coding=utf-8
from twisted.internet.protocol import Protocol,Factory
from twisted.protocols.basic import LineOnlyReceiver
from twisted.internet import reactor, defer
import pyamf
from pyamf.remoting.gateway.twisted import TwistedGateway
from twisted.web import server, resource
from pyamf.flex import ObjectProxy,ArrayCollection
class Chat(LineOnlyReceiver):
encoding = pyamf.AMF3
def updataRoom(self, handle, ordID,newID):
print "oldID : %d newID : %d" % (ordID,newID)##写到这里打包回家了。。。。
ordlist = []
newlist = []
for proto in self.clients:
if proto.room == ordID:
ordlist.append(proto.username)
if proto.room == newID:
newlist.append(proto.username)
for proto in self.clients:
if proto.room == ordID:
proto.writeObject(handle,ordlist)
if proto.room == newID:
proto.writeObject(handle,newlist)
def sendAll(self, handle, message, roomID):
print "roomID : %d" % (roomID)
for proto in self.clients:
if proto.room == roomID:
proto.writeObject(handle,message)
'''
x = ObjectProxy({"method":handle, "value":message})
print x
stream = pyamf.encode(x, encoding=pyamf.AMF3) #序列化
proto.transport.write(stream.getvalue())
'''
class SocketPolicyProtocol(Protocol):
"""
Serves strict policy file for Flash Player >= 9,0,124.