Establishes a socket, after joining the multicast group, the - (BOOL) onUdpSocket: (AsyncUdpSocket *) sock didReceiveData: (NSData *) data withTag: (long) tag fromHost: (NSString *) host port: (UInt16) port
After receiving the reply in a single step to start debugging, debugging to [self scheduleDequeueReceive];
Then skip this method
- (Void) scheduleDequeueReceive
{
if ((theFlags & kDequeueReceiveScheduled) == 0)
{
theFlags | = kDequeueReceiveScheduled;
[Self performSelector: @ selector (maybeDequeueReceive) withObject: nil afterDelay: 0 inModes: theRunLoopModes];
}
}
The [self performSelector: @ selector (maybeDequeueReceive) withObject: nil afterDelay: 0 inModes: theRunLoopModes];
This step, reported the following errors:
*** - [__NSArrayI Count]: message sent to deallocated instance 0x7830e90
Ask what is the solution? Urgent! ! !
Reply:
Explain:
[Self scheduleDequeueReceive];
And
- (Void) scheduleDequeueReceive methods are
AsyncUdpSocket.m file
Reply:
The - (BOOL) onUdpSocket: (AsyncUdpSocket *) sock didReceiveData: (NSData *) data withTag: (long) tag fromHost: (NSString *) host port: (UInt16) port inside the code stickers out to say. You are using the wrong memory has been released. Someone else's library does not have that problem, you do not have to change the code inside, then you do not have to post the code inside the database others out.
Reply:
- (BOOL) onUdpSocket: (AsyncUdpSocket *) sock didReceiveData: (NSData *) data withTag: (long) tag fromHost: (NSString *) host port: (UInt16) port
{
NSLog (@ "received data:% @", [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]);
NSLog (@ "% @", host);
if (tag == 1)
{
if ([[[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease] compare: @ "ihd"])
{
hostIP = [[NSString alloc] initWithString: host];
/ / [UdpSocket close];
}
}
if (tag == sn)
{
/ / First test whether you can get to the specified data stream
NSLog (@ "received data:% @", [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]);
}
return YES;
}
Reply:
Creating and calling part of the whole socket:
self.udpSocket = [[AsyncUdpSocket alloc] initWithDelegate: self];
[UdpSocket bindToPort: 8001 error: & error];
[UdpSocket enableBroadcast: YES error: & error];
[UdpSocket joinMulticastGroup: @ "224.0.0.1" error: & error];
[UdpSocket receiveWithTimeout: -1 tag: 1];
Receiving part:
- (BOOL) onUdpSocket: (AsyncUdpSocket *) sock didReceiveData: (NSData *) data withTag: (long) tag fromHost: (NSString *) host port: (UInt16) port
{
NSLog (@ "received data:% @", [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]);
NSLog (@ "% @", host);
if (tag == 1)
{
if ([[[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease] compare: @ "ihd"])
{
hostIP = [[NSString alloc] initWithString: host];
/ / [UdpSocket close];
}
}
if (tag == sn)
{
/ / First test whether you can get to the specified data stream
NSLog (@ "received data:% @", [[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]);
}
return YES;
}
Please help us to see
Reply:
The [udpSocket setRunLoopModes: [NSArray arrayWithObject: NSRunLoopCommonModes]]; Add to self.udpSocket = [[AsyncUdpSocket alloc] initWithDelegate: self]; behind to try
Reply:
Also reported the same problem
Reply:
Still the same problem
No comments:
Post a Comment