open port // TODO Start listening for incoming connections // Publish the service NSNetService *netService = [[NSNetService alloc] initWithDomain:@"" type:@"_myservice._tcp" name:@"" port:port]; netService.delegate = self; [netService publish];
actual port number struct sockaddr *addr = (struct sockaddr *)[[socketPort address] bytes]; int port; if (addr->sa_family == AF_INET) { port = ntohs(((struct sockaddr_in *)addr)->sin_port); } else if (addr->sa_family == AF_INET6) { port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port); }
[notification userInfo]; NSNumber *errorNo = [userInfo objectForKey:@"NSFileHandleError"]; if (errorNo) { /* Handle it */ } NSData *data = [userInfo objectForKey:NSFileHandleNotificationDataItem]; // TODO accumulate data, parse your protocol // Read more data when it becomes available [self.fileHandle readInBackgroundAndNotify]; }