                 s_t.writeBytes(bytes);
             });
         }
+
+        private static function parse_addr_spec(spec:String):Object
+        {
+            var parts:Array;
+            var addr:Object;
+
+            parts = spec.split(":", 2);
+            if (parts.length != 2 || !parseInt(parts[1]))
+                return null;
+            addr = {}
+            addr.host = parts[0];
+            addr.port = parseInt(parts[1]);
+
+            return addr;
+        }
     }
 }

                return;
            }
            puts("Facilitator spec: \"" + fac_spec + "\"");
            parts = fac_spec.split(":", 2);
            if (parts.length != 2 || !parseInt(parts[1])) {
                puts("Error: Facilitator spec must be in the form \"host:port\".");
                return;
            }
            fac_address = parts[0];
            fac_port = parseInt(parts[1]);

            go(TOR_ADDRESS, TOR_PORT);
        }

            puts("Facilitator: connected.");

            s_f.addEventListener(ProgressEvent.SOCKET_DATA, function (e:ProgressEvent):void {
                var client_spec:String;
                var client_addr:Object;

                client_spec = s_f.readMultiByte(e.bytesLoaded, "utf-8");
                puts("Facilitator: got \"" + client_spec + "\"");

                client_addr = parse_addr_spec(client_spec);
                if (!client_addr) {
                    puts("Error: Client spec must be in the form \"host:port\".");
                    return;
                }
                if (client_addr.host == "0.0.0.0" && client_addr.port == 0) {
                    puts("Error: Facilitator has no clients.");
                    return;
                }

                puts("Client: connecting to " + client_addr.host + ":" + client_addr.port + ".");
                s_c.connect(client_addr.host, client_addr.port);

            });

