0

I'm not well versed in networking but I'm firing up my own Bonjour service to find nearby users. I read this blog post and it says:

Socket represents a unique communication endpoint on the network. When your app needs to exchange data with another app, it creates a socket and uses it to connect to the other app’s socket. You can both send and receive data through the same socket. Each socket has an IP address and a port number (between 1 and 65535) associated with it. IP address uniquely identifies each computer on a given network and port number uniquely identifies a network socket on that computer.

NetServiceBrowser has a delegate method that discovers nearby users:

func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {

    print(service.domain)
    print(service.name)
    print(service.type)
    print(service.addresses as Any)
    print(service.hostName as Any)
    print(service.port)
}

It also has a method that I need to use to allow them to actually connect with each other:

func netService(_ sender: NetService,
                didAcceptConnectionWith inputStream: InputStream,
                outputStream stream: OutputStream) {
    print("netServiceDidAcceptConnection:\(sender)");
}

Once users are connected with each other and start sharing data I need to create an array with something that uniquely identifies each of them. I would like to use the device's IP Address but I don't see one returned from the didFind delegate method. What can I use in place to uniquely identify each device?

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256

0 Answers0