相关疑难解决方法(0)

AsyncUdpSocket如何使用receive

我正在尝试在模拟器上运行iPhone程序.我的问题是接收UDP数据.我使用asyncUdpSocket.如果我做一个插座并使用sendData:(NSData) toHost:,......好吧它工作正常.

想想我可能无法弄清楚接收功能是如何工作的.

我假设这样的事情:

socket = [[AsyncUdpSocket alloc] initWithDelegate:self];
[socket bindToPort:8000] error:nil] //returns YES
[socket receiveWithTimeout:-1 tag:1];  
Run Code Online (Sandbox Code Playgroud)

我相信它应该调用该方法 -(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long) fromHost:(NSString *)host port:(UInt16)port

好吧,我在该方法中放置了一个NSLog,它永远不会被调用.那么[socket receive,..]是唯一的接收方法,所以我想它应该是那个...或者是否有另一种方法我必须使用?或者我必须为我的代表或其他任何东西做一些补充......我只是无法弄清楚我是如何做到的

我搜索了asyncUdpSocket示例,教程,如何('s)等等,但我找不到一个例子.因此,如果有人想解释它或知道坐在一个很好的解释,将非常感激.

如果您还不知道答案,那么无论如何都要阅读!

iphone cocoa-touch udp asyncsocket

10
推荐指数
1
解决办法
1万
查看次数

iPhone UDP广播和响应

我需要从iPhone发送UDP广播,然后在超时期间收听UDP响应.我找到了Apple的UDPEcho示例,但我不确定这是否是我需要的.还发现这个例子发送但没有收到.基本上,我需要做一些像这样简单的事情:

//send the broadcast
SendUDP("255.255.255.255", targetPort, myData);
//A blocking call to get the data.  Timeout value will be short, 2 seconds at most
//An asynchronous option is ok, if it's necessary.
Response = GetFirstUDPResponse(receptionPort, timeoutValue);

//process the response
if(Response == null)
  //we timed out
else
  //process response
Run Code Online (Sandbox Code Playgroud)

我希望有一个简单的解决方案,我不必重新发明轮子.我很欣赏任何有关实施此策略的最佳策略的建议!

sockets iphone udp objective-c ios

8
推荐指数
2
解决办法
2万
查看次数

标签 统计

iphone ×2

udp ×2

asyncsocket ×1

cocoa-touch ×1

ios ×1

objective-c ×1

sockets ×1