# Path: swfconduit/event.py
# class Event( object ):
#     id = 0
#     timestamp = None
# 
#     def __init__( self ):
#         self.id         = getrandbits(29) # Size of an AMF3 integer field
#         self.timestamp  = datetime.now()
#         pass
# 
#     def fire( self, server, session ):
#         """ Perform the event's task """
#         pass
# 
#     # Tried this for AS3 readObject problem. May need in future
#     #def __readamf__( self, input ):
#     #    self.timestamp = input.readObject()
#     #    self.payload   = input.readObject()
#     #
#     #def __writeamf__( self, output ):
#     #    output.writeObject( self.timestamp )
#     #    output.writeObject( self.payload )
# 
#     def reply( self, cls, *args ):
#         """ Create a reply with the given class. Will set the reply's id field appropriately """
#         reply = cls(*args)
#         reply.id = self.id
#         return reply
# 
# Path: swfconduit/test.py
# class TickEvent( Event ):
#     def fire( self, server, session ):
#         print "Fired TickEvent"
# 
# class HelloEvent( Event ):
#     def fire( self, server, session ):
#         print "Fired HelloEvent"
#         session.sendEvent( TickEvent() )


import os, sys, types, time
import socket
import pyamf
from swfconduit.event import Event
from swfconduit.test import TickEvent, HelloEvent
    from optparse import OptionParser
"""


# Add current bin and lib directories
current_dir  = os.getcwd()
sys.path.append( current_dir )
sys.path.append( os.path.normpath( os.path.join( current_dir, "..", "lib" ) ) )


appPort = 7000
host    = '127.0.0.1'

pyamf.register_class( TickEvent, "swfconduit.test.TickEvent" )
pyamf.register_class( HelloEvent, "swfconduit.test.HelloEvent" )

class AmfSocketClient(object):
    encoding    = pyamf.AMF3

    def __init__(self):
        self.encoder    = pyamf.get_encoder( self.encoding )
        self.stream     = self.encoder.stream
        self.sock       = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.decoder    = pyamf.get_decoder( self.encoding )
        self.istream    = self.decoder.stream

    def connect(self, host, port):
        print "Connecting to socket server on %s:%d" % (host, port)
        try:
            self.sock.connect((host, port))
            print "Connected to server.\n"

# Path: swfconduit/event.py
# class Event( object ):
#     id = 0
#     timestamp = None
# 
#     def __init__( self ):
#         self.id         = getrandbits(29) # Size of an AMF3 integer field
#         self.timestamp  = datetime.now()
#         pass
# 
#     def fire( self, server, session ):
#         """ Perform the event's task """
#         pass
# 
#     # Tried this for AS3 readObject problem. May need in future
#     #def __readamf__( self, input ):
#     #    self.timestamp = input.readObject()
#     #    self.payload   = input.readObject()
#     #
#     #def __writeamf__( self, output ):
#     #    output.writeObject( self.timestamp )
#     #    output.writeObject( self.payload )
# 
#     def reply( self, cls, *args ):
#         """ Create a reply with the given class. Will set the reply's id field appropriately """
#         reply = cls(*args)
#         reply.id = self.id
#         return reply
# 
# Path: swfconduit/test.py
# class TickEvent( Event ):
#     def fire( self, server, session ):
#         print "Fired TickEvent"
# 
# class HelloEvent( Event ):
#     def fire( self, server, session ):
#         print "Fired HelloEvent"
#         session.sendEvent( TickEvent() )


# Path: bin/test.py
import os, sys, types, time
import socket
import pyamf
from swfconduit.event import Event
from swfconduit.test import TickEvent, HelloEvent
    from optparse import OptionParser

"""


# Add current bin and lib directories
current_dir  = os.getcwd()
sys.path.append( current_dir )
sys.path.append( os.path.normpath( os.path.join( current_dir, "..", "lib" ) ) )


appPort = 7000
host    = '127.0.0.1'

pyamf.register_class( TickEvent, "swfconduit.test.TickEvent" )
pyamf.register_class( HelloEvent, "swfconduit.test.HelloEvent" )

class AmfSocketClient(object):
    encoding    = pyamf.AMF3

    def __init__(self):
        self.encoder    = pyamf.get_encoder( self.encoding )
        self.stream     = self.encoder.stream
        self.sock       = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.decoder    = pyamf.get_decoder( self.encoding )
        self.istream    = self.decoder.stream

    def connect(self, host, port):
        print "Connecting to socket server on %s:%d" % (host, port)
        try:
            self.sock.connect((host, port))
            print "Connected to server.\n"

            event   = HelloEvent()