在 Red5 中创建线程时出错
首先,我在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论