1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
*************
ByteArray
*************
.. topic:: Introduction
This page describes how to setup the `ByteArray` example application
using the `Flex SDK`_ and :doc:`Django <../gateways/django>`.
The `ByteArray` class in Actionscript 3.0 provides methods and
properties to optimize reading, writing, and working with binary
data used in the Adobe Flash Player 9 and newer.
.. contents::
Overview
========
This example demonstrates how to:
- Create a webcam snapshot by capturing the `BitmapData` using Flex
- Wrap the image data with the `ByteArray` class and send it to a PyAMF
remoting gateway
- Use Python_ to write the JPG file to disk
- Run a simple webserver for static content that serves the JPG files
- Use Flex to load the JPG and display it in the application
A live demo can be found on the PyAMF blog_.
Download
========
Clone the PyAMF repository with:
.. code-block:: bash
git clone git://github.com/hydralabs/pyamf.git pyamf
cd doc/tutorials/examples/actionscript/bytearray/python
Alternatively, if you just want to have a look, you can browse_ the example online.
Gateway
=======
**Note**: Make sure you have Django_ >= 1.0 installed.
The remoting gateway for the Adobe Flash Player and Python AMF clients starts on
http://127.0.0.1:8000 when you launch the `development server`_:
.. code-block:: bash
python manage.py runserver
You should see something like:
.. code-block:: bash
Validating models...
0 errors found
Django version 1.1.1, using settings 'python.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
You can start the development server on a different host/port like this:
.. code-block:: bash
python manage.py runserver 192.168.1.100:8080
Clients
=======
Flash Player
------------
You can simply open the `SWF file`_ and it will connect to http://localhost:8000.
Press the 'Create snapshot' button to make snapshots and save them to disk. You
can see the snapshots in the View tab. The snapshots are saved in the
`python/gateway/images` folder.
.. image:: images/bytearrayexample.jpg
Python
------
The Python AMF client can be started by running the following from the `python`
folder:
.. code-block:: bash
python client.py
You should see something like this for the client:
.. code-block:: bash
Found 1 snapshot(s):
http://127.0.0.1:8000/images/django-logo.jpg
Saved snapshot:
snapshot_x_M527.jpg: http://127.0.0.1:8000/images/snapshot_x_M527.jpg
And the server prints:
.. code-block:: bash
[2009-12-26 14:08:15,023 root DEBUG] remoting.decode start
[2009-12-26 14:08:15,024 root DEBUG] Remoting target: u'getSnapshots'
[2009-12-26 14:08:15,024 root DEBUG] remoting.decode end
[2009-12-26 14:08:15,024 root DEBUG] AMF Request: <Envelope amfVersion=0>
(u'/1', <Request target=u'getSnapshots'>[]</Request>)
</Envelope>
[2009-12-26 14:08:15,026 root DEBUG] AMF Response: <Envelope amfVersion=0>
(u'/1', <Response status=/onResult>['http://127.0.0.1:8000/images/', ['jpg', 'png'],
<flex.messaging.io.ArrayCollection [{'name': 'django-logo.jpg'}]>]</Response>)
</Envelope>
[26/Dec/2009 14:08:15] "POST / HTTP/1.1" 200 149
[2009-12-26 14:08:15,032 root DEBUG] remoting.decode start
[2009-12-26 14:08:15,033 root DEBUG] Remoting target: u'ByteArray.saveSnapshot'
[2009-12-26 14:08:15,033 root DEBUG] remoting.decode end
[2009-12-26 14:08:15,033 root DEBUG] AMF Request: <Envelope amfVersion=0>
(u'/2', <Request target=u'ByteArray.saveSnapshot'>
[<pyamf.amf3.ByteArray object at 0x102266c08>, u'jpg']</Request>)
</Envelope>
[2009-12-26 14:08:15,034 root DEBUG] AMF Response: <Envelope amfVersion=0>
(u'/2', <Response status=/onResult>{'url': u'http://127.0.0.1:8000/images/snapshot_x_M527.jpg',
'name': u'snapshot_x_M527.jpg'}</Response>)
</Envelope>
Options
_______
When you run `python client.py --help` it will display the various options available
for this example client:
.. code-block:: bash
Usage: client.py [options]
Options:
-h, --help show this help message and exit
-p PORT, --port=PORT port number [default: 8000]
--host=HOST host address [default: 127.0.0.1]
.. _Flex SDK: http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK
.. _Django: http://djangoproject.com
.. _Python: http://python.org
.. _blog: http://blog.pyamf.org/2008/01/bytearray-example
.. _browse: http://github.com/hydralabs/pyamf/tree/master/doc/tutorials/examples/actionscript/bytearray
.. _development server: http://github.com/hydralabs/pyamf/tree/master/doc/tutorials/examples/actionscript/bytearray/python/manage.py
.. _SWF file: http://github.com/hydralabs/pyamf/tree/master/doc/tutorials/examples/actionscript/bytearray/flex/deploy/bytearray.swf
|