I'm trying to use GCDAsyncSocket to establish a peer to peer connection between my Mac and my iPhone. Currently both devices are connected under the same wifi. But using the method:
[asyncSocket connectToHost:@"my iPhone's IP address" onPort:80 error:&err]
does not work. Is it due to my false operation? Could you please explain how to set up a peer to peer connection under my circumstance?
I've found out a way to do that. If you're using GCDAsyncSocket, there's a demo called BonjourServer & BonjourClient. In its code, there's a delegate method:
- (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket
{
DDLogInfo(@"Accepted new socket from %@:%hu", [newSocket connectedHost], [newSocket connectedPort]);
// The newSocket automatically inherits its delegate & delegateQueue from its parent.
[connectedSockets addObject:newSocket];
connectedSocket = newSocket;
}
When you set up a peer to peer connection between the server and client, you can send data in the method specified above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.