实在是不好意思,昨天出去一天有事,没能及时的上网。feiyuegaoshan(飞跃):你的方法好像并不可行。我也认为这个该是错误提示。 关于这个错误本身是什么原因呢,我使用的是JMF里的rtp方式传语音信息。 所有的东西,都是人家sun &IBM封装好了的,也不知道人家底层是如何实现的。从could not set timeout on socket可以看出,他是用socket来实现的rtp和rtcp。 我想rtp用的该是UDP socket. rtcp用的该是TCP socket. 请大家探讨一下,这里的could not set timeout on socket 到底是那类的socket出现问题。我个人认为是rtcp用的TCP socket出现了问题,因为UDP socket 条件没有那么苛刻。
catch(Error e) { } 试试.
我查找了所有的关于:ServerSocket ,Socket,DatagramScoket,DatagramPacket 的函数。 都没有出现 “could not set timeout on socket ”错误提示的函数。
错误不一定能捕获,就是err
try
{}
catch(Throwable t)
{
System.out.println(t.toString());
}
关于这个错误本身是什么原因呢,我使用的是JMF里的rtp方式传语音信息。
所有的东西,都是人家sun &IBM封装好了的,也不知道人家底层是如何实现的。从could not set timeout on socket可以看出,他是用socket来实现的rtp和rtcp。
我想rtp用的该是UDP socket. rtcp用的该是TCP socket.
请大家探讨一下,这里的could not set timeout on socket 到底是那类的socket出现问题。我个人认为是rtcp用的TCP socket出现了问题,因为UDP socket 条件没有那么苛刻。
{
}
试试.
都没有出现 “could not set timeout on socket ”错误提示的函数。
会不会是某个背后运行的线程出现了错误?但是那样的话也应该被看到执行过程啊,毕竟某一个时间,cpu只能被一个线程所用,可是什么没有,在当前线程的某个位置突然就出现这个错误。
{
try {
InetAddress ipAddr;
SessionAddress destAddr;
SessionLabel session;
// Open the RTP sessions.
for (int i = 0; i < sessions.length; i++) { // Parse the session addresses.
try {
session = new SessionLabel(sessions[0]); } catch (IllegalArgumentException e) {
System.err.println("Failed to parse the session address given: " + sessions[0]);
return false;
} System.err.println(" - Open RTP session for: addr: " + session.addr + " port: " + session.port + " ttl: " + session.ttl); mgrs[i].addSessionListener(this);
mgrs[i].addReceiveStreamListener(this); ipAddr = InetAddress.getByName(session.addr); if( ipAddr.isMulticastAddress()) {
destAddr = new SessionAddress( ipAddr,
session.port,
session.ttl); } else {
destAddr = new SessionAddress( ipAddr,
session.port);
}
try{
mgrs[0].addTarget(destAddr);//问题出现之处,屏蔽掉这一句就OK了,
//当然程序也就不能达到目的了
}
catch(Error t)
{
System.out.println(t.toString());
}
} } catch (Exception e){
System.err.println("Cannot create the RTP Session: " + e.getMessage());
return false;
}
return true;
}
过程如下:
[1]申明一个RTPManager用于管理接收
RTPManager mgr;
[2]实例化RTPManager
mgr = (RTPManager) RTPManager.newInstance();
[3]初始化RTPManager:
mgr.initialize( localAddr);//localAddr为本地地址
mgr.addTarget(desAddr);//远端地址
[4]加上RTPManager的监听器
mgr.addSessionListener(this);
mgr.addReceiveStreamListener(this);
//其中的this当然是实现了SessionListener和ReceiveStreamListener的this.这样就可以收听希望有更多的人学习JMF.Sun ONE中有很多好东西。JMF,JavaTV,Java Phone.