Forum Xamarin Xamarin.iOS

NSNetService Assign IP Address using C#

RajKulkarni.0951RajKulkarni.0951 USMember ✭✭
edited September 2019 in Xamarin.iOS

Using Python link I am able to publish a service set the IP address that I want to connect to when user selects the device in control Center. Below is the Code for Python. Now using NSNetService in C# I am trying to achieve same thing. Publish is working but adding the IP address socket.inet_aton("10.100.X.XX") To NSNet service I am unable to achieve that in C#. Please post some guidelines to achieve. How can I add the IP address to the NSNETService to show that IP address in NSNetBrowser.

        _testService = new NSNetService("_airplay._tcp.local.", "_testservice._tcp", "Test Service", 7000);
        _testService.Published += delegate (object sender, EventArgs e) {
            NSNetService ns = sender as NSNetService;
            Console.WriteLine("Bonjour published service '{0}'", ns.Name);
        _testService.WillPublish += delegate (object sender, EventArgs e) {
            NSNetService ns = sender as NSNetService;
            Console.WriteLine("Bonjour will publish service '{0}'", ns.Name);
        _testService.PublishFailure += delegate (object sender, NSNetServiceErrorEventArgs e) {
            NSNetService ns = sender as NSNetService;
            Console.WriteLine("Bonjour failed to publish service '{0}'", ns.Name);
        }; this

import logging
import socket
import sys
from time import sleep

from zeroconf import ServiceInfo, Zeroconf

if name == 'main':
if len(sys.argv) > 1:
assert sys.argv[1:] == ['--debug']

airplay_desc = {'deviceid': '00:05:a6:16:45:4b',
                'features': '0xA7FFFF7,0xE',
                'flags':    '0x4',
                'model':    'AppleTV5,3',
                'pi':       '6b448552-85ce-4143-a896-e28d12e8a0ab',
                'pk':       'F381DC574DEAF9C70B75297755BC7C7C35BB1D0DB500258F3AB46B5FE7C7355B',
                'srcvers':  '220.68',
                'vv':       '2'}

airplay_info = ServiceInfo("_airplay._tcp.local.",
                   socket.inet_aton("10.100.XXX.XX"), 7000, 0, 0,

raop_desc = {'am': 'AppleTV5,3',

raop_info = ServiceInfo("_raop._tcp.local.",
                   "[email protected]_raop._tcp.local.",
                   socket.inet_aton("10.100.X.XX"), 7000, 0, 0,

zeroconf = Zeroconf()
print("Registration of a service, press Ctrl-C to exit...")
zeroconf.register_service(raop_info, allow_name_change=True)

    while True:
except KeyboardInterrupt:


  • LandLuLandLu Member, Xamarin Team Xamurai

    The first parameter in the constructor is the domain configuration of your NSNetService.
    You set it to "_airplay._tcp.local." in your sample you posted above.

  • @LandLu: Thank you for the response.Are you recommending this ("", "_testservice._tcp", "Test Service", 7000);
    I need to assign IP address to NSNetService and I have tried this. it does not work. Please let me know if you have anything else. Thanks!

Sign In or Register to comment.