在 Red5 中创建线程时出错

发布于 2024-11-16 01:36:06 字数 5053 浏览 0 评论 0原文

首先,我在java应用程序中成功创建了线程。然后,我尝试将其引入 Red5 应用程序,但它显示错误,我无法再解决。

我的代码,像这样:

import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.so.ISharedObject;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import net.sf.asterisk.manager.AuthenticationFailedException;
import net.sf.asterisk.manager.ManagerConnection;
import net.sf.asterisk.manager.ManagerConnectionFactory;
import net.sf.asterisk.manager.TimeoutException;
import net.sf.asterisk.manager.action.CommandAction;
import net.sf.asterisk.manager.response.CommandResponse;

class UserOnline extends Thread{
    private ManagerConnection c;
     public LinkedList<String> listtUser;
     private LinkedList<String> sendList = new LinkedList<String>();
        public UserOnline()
        {
            start();
        }
        public void run()
        {
            try {
                c = new ManagerConnectionFactory().getManagerConnection("localhost", 
                        "admin", "secret5");
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                c.login();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (AuthenticationFailedException e) {
                e.printStackTrace();
            } catch (TimeoutException e) {
                e.printStackTrace();
            }
            CommandResponse response =  new CommandResponse();
            listtUser = new LinkedList<String>();
            CommandAction action;
            Iterator lineIterator;
            while (true){
                action = new CommandAction();
                action.setCommand("sip show peers");
                try {
                    response = (CommandResponse) c.sendAction(action);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (TimeoutException e) {
                    e.printStackTrace();
                }
                lineIterator = response.getResult().iterator();
                //int i=0;
                while (lineIterator.hasNext())
                {
                    listtUser.add(lineIterator.next().toString());          
                    //System.out.println(listtUser.get(i));
                    //i++;
                }
                parseList(listtUser);
                listtUser.clear();
                //c.logoff();
                try {
                    Thread.currentThread().sleep(5000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
        }

    public void parseList(LinkedList<String> llUser){
        llUser.removeFirst();
        llUser.removeLast();
        String[] node;
        for(String s : llUser) {
            //System.out.println(s);
            node = s.split(" ");
            if(!s.contains("Unspecified")){
                //System.out.println(node[0]+" online");
                sendList.add(node[0]+"-online");
            }
            else if(s.contains("Unspecified")){
                //System.out.println(node[0]+" offline");
                sendList.add(node[0]+"-offline");
            }
        }
        for(String t : sendList){
            System.out.println(t);
        }
        this.getListUser();
        sendList.clear();
        //index=0;          
    }
    public List<String> getListUser(){
        return sendList;
    }
}

    public class Application extends ApplicationAdapter {
        /** {@inheritDoc} */
        private IScope apScope;
        @Override
        public boolean connect(IConnection conn, IScope scope, Object[] params) {
            apScope = scope;
            createSharedObject(apScope, "user", false);
            //sendUserOnline();
            return true;
        }

    /** {@inheritDoc} */
    @Override
    public void disconnect(IConnection conn, IScope scope) {
        super.disconnect(conn, scope);
    }

    public void sendUserOnline(){
        UserOnline uso = new UserOnline();
        uso.start();
        List<String> listUserStatus = new LinkedList<String>();
        ISharedObject so = getSharedObject(apScope, "user");
        try {
            uso = new UserOnline();
            listUserStatus = uso.getListUser();
            so.sendMessage("receiveUserStatus", listUserStatus);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

它显示这样的错误:

[INFO] [NioProcessor-1] org.red5.server.adapter.MultiThreadedApplicationAdapter
- W3C x-category:session x-event:disconnect c-ip:127.0.0.1 c-client-id:0

请帮忙,提前致谢

First, I successfully created thread in java application. Then, I tried to bring it in Red5 application but it showed error that i couldn't solve anymore.

My code, like this:

import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.so.ISharedObject;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import net.sf.asterisk.manager.AuthenticationFailedException;
import net.sf.asterisk.manager.ManagerConnection;
import net.sf.asterisk.manager.ManagerConnectionFactory;
import net.sf.asterisk.manager.TimeoutException;
import net.sf.asterisk.manager.action.CommandAction;
import net.sf.asterisk.manager.response.CommandResponse;

class UserOnline extends Thread{
    private ManagerConnection c;
     public LinkedList<String> listtUser;
     private LinkedList<String> sendList = new LinkedList<String>();
        public UserOnline()
        {
            start();
        }
        public void run()
        {
            try {
                c = new ManagerConnectionFactory().getManagerConnection("localhost", 
                        "admin", "secret5");
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                c.login();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (AuthenticationFailedException e) {
                e.printStackTrace();
            } catch (TimeoutException e) {
                e.printStackTrace();
            }
            CommandResponse response =  new CommandResponse();
            listtUser = new LinkedList<String>();
            CommandAction action;
            Iterator lineIterator;
            while (true){
                action = new CommandAction();
                action.setCommand("sip show peers");
                try {
                    response = (CommandResponse) c.sendAction(action);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (TimeoutException e) {
                    e.printStackTrace();
                }
                lineIterator = response.getResult().iterator();
                //int i=0;
                while (lineIterator.hasNext())
                {
                    listtUser.add(lineIterator.next().toString());          
                    //System.out.println(listtUser.get(i));
                    //i++;
                }
                parseList(listtUser);
                listtUser.clear();
                //c.logoff();
                try {
                    Thread.currentThread().sleep(5000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
        }

    public void parseList(LinkedList<String> llUser){
        llUser.removeFirst();
        llUser.removeLast();
        String[] node;
        for(String s : llUser) {
            //System.out.println(s);
            node = s.split(" ");
            if(!s.contains("Unspecified")){
                //System.out.println(node[0]+" online");
                sendList.add(node[0]+"-online");
            }
            else if(s.contains("Unspecified")){
                //System.out.println(node[0]+" offline");
                sendList.add(node[0]+"-offline");
            }
        }
        for(String t : sendList){
            System.out.println(t);
        }
        this.getListUser();
        sendList.clear();
        //index=0;          
    }
    public List<String> getListUser(){
        return sendList;
    }
}

    public class Application extends ApplicationAdapter {
        /** {@inheritDoc} */
        private IScope apScope;
        @Override
        public boolean connect(IConnection conn, IScope scope, Object[] params) {
            apScope = scope;
            createSharedObject(apScope, "user", false);
            //sendUserOnline();
            return true;
        }

    /** {@inheritDoc} */
    @Override
    public void disconnect(IConnection conn, IScope scope) {
        super.disconnect(conn, scope);
    }

    public void sendUserOnline(){
        UserOnline uso = new UserOnline();
        uso.start();
        List<String> listUserStatus = new LinkedList<String>();
        ISharedObject so = getSharedObject(apScope, "user");
        try {
            uso = new UserOnline();
            listUserStatus = uso.getListUser();
            so.sendMessage("receiveUserStatus", listUserStatus);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

it showed error like this:

[INFO] [NioProcessor-1] org.red5.server.adapter.MultiThreadedApplicationAdapter
- W3C x-category:session x-event:disconnect c-ip:127.0.0.1 c-client-id:0

please help, thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文