如何检测 SCTP 连接失败

How to detect SCTP connection failuer

我正在使用 mobicents CAP 实现为 CAMEL 计费构建 CAP 应用程序;我的应用程序工作正常,我可以在 SSF 和 SCF 之间发送和接收消息。 我正在寻找的是:如何检测到客户端和服务器之间的 SCTP link 已损坏?因为当我故意停止服务器并保留客户端 运行 时,发送 CAPDialog 不会引发任何错误。

当我停止服务器时,在控制台上我看到以下异常:

2015-04-14 13:15:29,669 [Thread-0 ] ERROR org.mobicents.protocols.sctp.SelectorThread - Exception while finishing connection for Association=clientAsscoiation
java.net.ConnectException: Connection refused: no further information
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
    at org.mobicents.protocols.sctp.SelectorThread.finishConnectionTcp(SelectorThread.java:407)
    at org.mobicents.protocols.sctp.SelectorThread.finishConnection(SelectorThread.java:368)
    at org.mobicents.protocols.sctp.SelectorThread.run(SelectorThread.java:151)
    at java.lang.Thread.run(Unknown Source)

在此期间,如果我尝试发送 CAPDialog,例如发送一个 oAnswer 事件,它不会告诉请求是否成功(在我的情况下理想情况下应该 return 失败)

OAnswerSpecificInfo oAnswerSpecificInfo = this.getCapProvider().getCAPParameterFactory().createOAnswerSpecificInfo(null,
                    false, false, null, null, null);
ReceivingSideID legID = this.getCapProvider().getCAPParameterFactory().createReceivingSideID(LegType.leg2);
MiscCallInfo miscCallInfo = this.getCapProvider().getINAPParameterFactory().createMiscCallInfo(MiscCallInfoMessageType.notification, null);
EventSpecificInformationBCSM eventSpecificInformationBCSM = this.getCapProvider()
                    .getCAPParameterFactory()
                    .createEventSpecificInformationBCSM(oAnswerSpecificInfo);

 CAPDialogCircuitSwitchedCall capDialog = (CAPDialogCircuitSwitchedCall) getCapProvider().getCAPDialog(localDialogId);

 capDialog.addEventReportBCSMRequest(EventTypeBCSM.oAnswer, eventSpecificInformationBCSM, legID, miscCallInfo, null);
 capDialog.setUserObject(getParamAsString("referenceId"));
 capDialog.setReturnMessageOnError(true);
 capDialog.send();

"capDialog.send();" 代码不会 return 返回错误,即使任何底层 SS7 link 已关闭。

如果您有权访问 SCTP 堆栈,则可以检查 SCTP 连接是打开还是关闭: 协会协会= ...; association.isConnected();