public byte[] encodeConnect(Map<String, Object> params) throws EncodingException, NotImplementedException
	{
		List<Byte> result = new ArrayList<Byte>();

		writeStringAMF0(result, "connect");
		writeIntAMF0(result, 1); // invokeId

		// Write params
		result.add((byte)0x11); // AMF3 object
		result.add((byte)0x09); // Array
		writeAssociativeArray(result, params);

		// Write service call args
		result.add((byte)0x01);
		result.add((byte)0x00); // false
		writeStringAMF0(result, "nil"); // "nil"
		writeStringAMF0(result, ""); // ""

		// Set up CommandMessage
		TypedObject cm = new TypedObject("flex.messaging.messages.CommandMessage");
		cm.put("messageRefType", null);
		cm.put("operation", 5);
		cm.put("correlationId", "");
		cm.put("clientId", null);
		cm.put("destination", "");
		cm.put("messageId", randomUID());
		cm.put("timestamp", 0d);
		cm.put("timeToLive", 0d);
		cm.put("body", new TypedObject(null));
		Map<String, Object> headers = new HashMap<String, Object>();
		headers.put("DSMessagingVersion", 1d);
		headers.put("DSId", "my-rtmps");
		cm.put("headers", headers);

		// Write CommandMessage
		result.add((byte)0x11); // AMF3 object
		encode(result, cm);

		byte[] ret = new byte[result.size()];
		for (int i = 0; i < ret.length; i++)
			ret[i] = result.get(i);

		ret = addHeaders(ret);
		ret[7] = (byte)0x14; // Change message type

		return ret;
	}