在我的应用程序中,我做的事与WiTap项目中的操作非常相似。我使用Bonjour发现对等体,然后通过套接字发送数据以执行初始握手。
我能够看到使用Cocoa Packet Analyzer发送数据的OTA。但是stream: handleEvent:
函数永远不会在接收对等方调用。
我能看到的是:
NSStreamEventErrorOccurred
错误。当上述行为发生时,我无法看到任何明显的模式。
以下是一些可能有用的代码。
PacketSender和PacketReceiver对象是单例。 我已多次验证在调试时将这些对象的正确(且唯一)实例设置为委托:
if (![netService getInputStream:&_inStream outputStream:&_outStream])
{
[Utilities showAlert:@"Failed connecting to server"];
return BM_ERROR_NETSERVICE_STREAM_FAIL;
}
if(!sharedProtocolManager.mPacketSender)
{
sharedProtocolManager.mPacketSender = [PacketSender sharedSender];
}
if(!sharedProtocolManager.mPacketReceiver)
{
sharedProtocolManager.mPacketReceiver = [PacketReceiver sharedReceiver];
}
if(!sharedProtocolManager.mPacketSender || !sharedProtocolManager.mPacketReceiver)
{
return BM_ERROR_FAIL;
}
[PacketReceiver setupInStream:_inStream];
[PacketSender setupOutStream:_outStream];
}
在PacketReceiver setupInStream:function中我有:
if (sharedPacketReceiver->mInStream != inStream)
{
[sharedPacketReceiver->mInStream release];
sharedPacketReceiver->mInStream = [inStream retain];
}
sharedPacketReceiver->mInStream.delegate = sharedPacketReceiver;
对于进一步调试此方法的任何答案甚至建议都将非常感激。
谢谢!