NSNetService Assign IP Address using C#

RajKulkarni.0951RajKulkarni.0951 USMember ✭✭
edited September 20 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':
logging.basicConfig(level=logging.DEBUG)
if len(sys.argv) > 1:
assert sys.argv[1:] == ['--debug']
logging.getLogger('zeroconf').setLevel(logging.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.",
                   "SLP._airplay._tcp.local.",
                   socket.inet_aton("10.100.XXX.XX"), 7000, 0, 0,
                   airplay_desc)

raop_desc = {'am': 'AppleTV5,3',
             'ch':'2',
             'cn':'0,1,2,3',
             'da':'true',
             'ek':'1',
             'et':'0,3,5',
             'md':'0,1,2',
             'pw':'false',
             'sm':'false',
             'sr':'44100',
             'ss':'16',
             'sv':'false',
             'tp':'UDP',
             'tx':'vers=1',
             'vn':'65537',
             'vs':'220.68',
             'sf':'0x4',
             'ft':'0xA7FFFF7,0xE',
             'pk':'F381DC574DEAF9C70B75297755BC7C7C35BB1D0DB500258F3AB46B5FE7C7355B',
             'vv':'2'}

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

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

try:
    while True:
        sleep(0.1)
except KeyboardInterrupt:
    pass
finally:
    print("Unregistering...")
    zeroconf.unregister_service(airplay_info)
    zeroconf.close()

Answers

  • 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.

  • RajKulkarni.0951RajKulkarni.0951 USMember ✭✭

    @LandLu: Thank you for the response.Are you recommending this ("10.112.56.22", "_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.