Hi guys,

Here goes the code for RTMP client simulation. Please watch out for the 
package name. This works nicely!
-------------------------------------------------------------------------------------------------------------------------------------------------------
package org.red5.server.webapp.echo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.apache.commons.lang.RandomStringUtils;
import org.red5.io.utils.ObjectMap;
import org.red5.server.api.IConnection;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.net.rtmp.MyRTMPClient;

/**
 * A simple client simulation
 */
public class TestClient  {
    public static void main(String[] args) {

        List<String> userNames = new ArrayList<String>();
        userNames.add("sri");
        userNames.add("something");

        for (String name : userNames) {

            try {
                Thread t = new Thread(new MyCallback(name));
                Thread.sleep(5000);
                t.start();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    static class MyCallback implements Runnable {

        MyRTMPClient client = new MyRTMPClient();

        List<String> actions = new ArrayList<String>();

        protected static final ThreadLocal<IConnection> currentSession = 
new ThreadLocal<IConnection>();

        static boolean created = false;

        IConnection conn = null;

        public MyCallback(String name) {
            init(name);
        }

        public void run() {

            try {
                Red5.setConnectionLocal(conn);
                while (true) {

                    client.invoke("yourService.method1", new Object[] {
                            "firstparam","secondparam"},
                            new IPendingServiceCallback() {
                                public void 
resultReceived(IPendingServiceCall call) {
                                    System.err.println("Result Received: "
                                            + call.getResult());
                                }
                            });

                    client.invoke("anotherService.anotherMethod",
                            new Object[] {
                                    1,3}, new IPendingServiceCallback() {
                                public void 
resultReceived(IPendingServiceCall call) {
                                    System.err.println("Result Received: "
                                            + call.getResult());
                                }
                            });

                                   
                    Thread.sleep(5000);
                    client.invoke("anotherService.anotherMethod2", new 
Object[] {"2",true },
                            new IPendingServiceCallback() {
                                public void 
resultReceived(IPendingServiceCall call) {
                                    System.err.println("Result Received: "
                                            + call.getResult());
                                }
                            });
                   
                    Thread.sleep(10000);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        private void init(String login) {
            ObjectMap<String, Object> params = new ObjectMap<String, 
Object>();

            params.put("app", "yourapp/room/3354");
            params.put("tcUrl", "rtmp://192.168.253.85/yourapp/room/3354");

            Map<String, Object> tparams = new HashMap<String, Object>();
            tparams.put("password", "password");
            tparams.put("username", login);
            Object[] obj = new Object[] { tparams };
            client.connect("192.168.253.85", 1935, params, obj,
                    new IPendingServiceCallback() {
                        public void resultReceived(IPendingServiceCall 
call) {
                            System.err.println("Second result Received: "
                                    + call.getResult() + "::"
                                    + Red5.getConnectionLocal().hashCode());

                            conn = Red5.getConnectionLocal();

                        }
                    });
        }
    }

}



_______________________________________________
Red5 mailing list
[email protected]
http://osflash.org/mailman/listinfo/red5_osflash.org

Reply via email to