swift – iOS UDP: write to socket, then hear constantly


Setup: A tool with a digital camera, an iPhone.

  1. A cellphone connects to the machine’s wi-fi community. I determine the gateway (on this case the machine’s IP) through NWPathMonitor.
  2. I have to ship “begin” command to the machine’s IP and a particular port (say, 192.168.5.1:12345). For that I set up NWConnection and ship knowledge when prepared through connection.ship(content material:completion:).
  3. The machine then begins to constantly write within the connection’s port. However utilizing the Apple’s Community lib I can solely get the response as soon as through connection.receiveMessage(completion:) and such. I might have listened with NWListener, however on this use case I can not, since I’ve to jot down first after which hear for responses. And even after I create a Listener on the connection’s port (from the cellphone’s facet) (with allowLocalEndpointReuse, if it issues), nothing occurs.
  4. Once I’m completed, I have to ship “cease” on this very socket.

I experimented with some Mac device referred to as “PacketSender” and it receives all of the responses alright, after I ship a “begin” command, till I ship “cease”. Is that this a limitation of the Community lib, ought to I take advantage of another device, or do I miss one thing?

Thanks!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles