Table of Contents

  1. Download
  2. Server
  3. Client

Binary Socket Howto

This page describes how to setup the Socket Flex example application.
The Socket class enables code to make socket connections and to read and write raw binary data.
This example shows how to setup a Socket connection and exchange AMF data.

There is a live demo available on the PyAMF blog.

Download

Grab the example from SVN with:

svn co http://svn.pyamf.org/examples/trunk/socket socket-example
cd socket-example/python

Alternatively, if you just want to have a look at the source, you can browse the example source online.

Server

The Twisted socket server for the Flash/AMF client starts on http://localhost:8000 when you run:

twistd -noy timer.tac

Note: make sure you have Twisted >= 2.5 installed.

You should see something like:

2008-01-07 06:03:09+0100 [-] Log opened.
2008-01-07 06:03:09+0100 [-] twistd 2.5.0 (../Python 2.5.1) starting up
2008-01-07 06:03:09+0100 [-] reactor class: <class 'twisted.internet.selectreactor.SelectReactor'>
2008-01-07 06:03:09+0100 [-] server.TimerFactory starting on 8000
2008-01-07 06:03:09+0100 [-] Starting factory <server.TimerFactory instance at 0x1414af8>

You can stop the server by pressing Ctrl-c

Client

You can simply open the SWF file and it will connect to http://localhost:8000.
Use the 'Start' and 'Stop' buttons to control the Python socket server that sends the system time to the Flex application every second:

Attachments