Implementation of IOS using socket UDP protocol broadcasting mechanism

Source: Internet
Author: User
<span id="Label3"></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#272ad8">1.</span> <span style="font-family:‘Heiti SC Light‘">Preface</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">What is the <span style="font-family:Menlo">UDP</span> Protocol broadcast mechanism?</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">Take an example, for<span style="font-family:Menlo"> </span> example, in a group of people, a person to find Zhang san, so you shout to the crowd <span style="font-family:Menlo">(</span> broadcast <span style="font-family:Menlo">)</span>:<span style="font-family:Menlo">"</span> who is Zhang San <span style="font-family:Menlo">"</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">If it is Zhang san, it will respond to you, and it is the same in the Network.</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; min-height:16px"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">Application Scenarios for <span style="font-family:Menlo">UDP</span> broadcast mechanism:</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">A number of clients, in the LAN <span style="font-family:Menlo">(</span> do not know the case of <span style="font-family:Menlo">IP</span> <span style="font-family:Menlo">)</span> need to find a number of devices unique equipment, such as the server, or a printer, fax machines and so On.</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">Let's say I'm now ready to install the server on an <span style="font-family:Menlo">IPad</span> that never loses power.</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">A number of clients <span style="font-family:Menlo">IPhone</span> is activated, it is necessary to broadcast to all devices, who is the server, the server, please tell me the <span style="font-family:Menlo">IP</span> address. Then I went to connect and then entered the long connection and received the message Backstage.</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo; color:rgb(39,42,216)">2.</span>implementation of<span style="font-family:Menlo">UDP</span> broadcast mechanism</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">Note:<span style="font-family:Menlo">iPad:</span> server-side <span style="font-family:Menlo">iPhone:</span> Client</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo; color:rgb(39,42,216)">2.1</span> <span style="font-family:Menlo">.</span> Server-side (<span style="font-family:Menlo">IPad</span>) implementations</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(0,132,0)"><span style="font-family:‘Heiti SC Light‘">Initialize</span> UDP</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">Asyncudpsocket *asyncudpsocket = [[asyncudpsocket alloc] initwithdelegate:<span style="color:#bb2ca2"></span>self];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(39,42,216)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(39,42,216)"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> bound port</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#703daa">nserror</span> *err =<span style="color:#bb2ca2">nil</span>;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">[asyncudpsocket enablebroadcast:<span style="color:#bb2ca2">YES</span> error:&err];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">[asyncudpsocket bindtoport:<span style="color:#272ad8">9527</span> error:&err];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> start the receive thread</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">[asyncudpsocket receivewithtimeout:-<span style="color:#272ad8">1</span> tag:<span style="color:#272ad8">0</span>];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><span style="font-family:Menlo; color:rgb(39,42,216)">2.1.1</span> <span style="font-family:Menlo">.</span> Implementing Proxy methods</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> received a message</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">BOOL</span>) onudpsocket: (asyncudpsocket *) sock didreceivedata: (<span style="color:#703daa">nsdata</span> *) data withtag: (<span style="color:#bb2ca2">long</span>) Tag fromhost: (<span style="color:#703daa">nsstring</span> *) host port: (<span style="color:#703daa">UInt16</span>) port{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#bb2ca2">if</span> (data <span style="font-family:‘Heiti SC Light‘">is for the server</span> ) {</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo; color:rgb(0,0,0)"></span> <span style="font-family:Menlo"></span> <span style="font-family:Menlo"></span> <span style="font-family:Menlo"></span> <span style="font-family:Menlo"></span> //based on the IP given by the client, the communication can be started by using TCP or UDP to connect to each other. <span style="color:#000000">      </span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}<span style="font-family:‘Heiti SC Light‘">  </span><span style="color:#bb2ca2">return</span><span style="color:#bb2ca2">YES</span>;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> did not receive the message</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) onudpsocket: (asyncudpsocket *) sock didnotreceivedatawithtag: (<span style="color:#bb2ca2">long</span>) tag duetoerror: ( <span style="color:#703daa"> Nserror</span> *) error{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> did not send out a message</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) onudpsocket: (asyncudpsocket *) sock didnotsenddatawithtag: (<span style="color:#bb2ca2">long</span>) tag duetoerror: ( <span style="color:#703daa"> Nserror</span> *) error{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> sent out message</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) onudpsocket: (asyncudpsocket *) sock didsenddatawithtag: (<span style="color:#bb2ca2">long</span>) tag{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> Disconnect</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) onudpsocketdidclose: (asyncudpsocket *) sock{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><br><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#272ad8">2.2</span>. <span style="font-family:‘Heiti SC Light‘">The implementation of the</span> <span style="font-family:‘Heiti SC Light‘">client (</span>iPhone)</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘">Note: The implementation steps are similar to the server side</p></p><span style="color:rgb(0,132,0); font-family:Menlo; font-size:14px"><span style="color:rgb(0,132,0); font-family:Menlo; font-size:14px">//</span></span><span style="color:rgb(0,132,0); font-size:14px; font-family:‘Heiti SC Light‘"><span style="color:rgb(0,132,0); font-size:14px; font-family:‘Heiti SC Light‘">Initialize</span></span><span style="color:rgb(0,132,0); font-family:Menlo; font-size:14px"><span style="color:rgb(0,132,0); font-family:Menlo; font-size:14px">UDP</span></span><br><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">Asyncudpsocket *asyncudpsocket = [[asyncudpsocket alloc] initwithdelegate:<span style="color:#bb2ca2"></span>self];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:rgb(0,132,0); font-size:14px; font-family:Menlo">//</span> <span style="color:rgb(0,132,0); font-family:‘Heiti SC Light‘; font-size:14px">Binding Port</span><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#703daa">nserror</span> *err =<span style="color:#bb2ca2">nil</span>;</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">[asyncudpsocket enablebroadcast:<span style="color:#bb2ca2">YES</span> error:&err];</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">[asyncudpsocket bindtoport:<span style="color:#272ad8">9527</span> error:&err];</p></p><br><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><span style="color:#272ad8">2.2.1</span>. <span style="font-family:‘Heiti SC Light‘">Implementing Proxy Methods</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> received a message</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">BOOL</span>) onudpsocket: (asyncudpsocket *) sock didreceivedata: (<span style="color:#703daa">nsdata</span> *) data withtag: (<span style="color:#bb2ca2">long</span>) Tag fromhost: (<span style="color:#703daa">nsstring</span> *) host port: (<span style="color:#703daa">UInt16</span>) port{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(187,44,162)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(187,44,162)"><span style="color:#000000"></span>return<span style="color:#000000">YES</span><span style="color:#000000"></span> ; <span style="font-family:‘Heiti SC Light‘; color:rgb(0,0,0)"> </span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> did not receive the message</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) onudpsocket: (asyncudpsocket *) sock didnotreceivedatawithtag: (<span style="color:#bb2ca2">long</span>) tag duetoerror: ( <span style="color:#703daa"> Nserror</span> *) error{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> did not send out a message</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) onudpsocket: (asyncudpsocket *) sock didnotsenddatawithtag: (<span style="color:#bb2ca2">long</span>) tag duetoerror: ( <span style="color:#703daa"> Nserror</span> *) error{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> sent out message</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) onudpsocket: (asyncudpsocket *) sock didsenddatawithtag: (<span style="color:#bb2ca2">long</span>) tag{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:‘Heiti SC Light‘; color:rgb(0,132,0)"><span style="font-family:Menlo">//</span> Disconnect</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) onudpsocketdidclose: (asyncudpsocket *) sock{</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">}</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><br></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(39,42,216)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(39,42,216)">2.2.2<span style="color:#000000">.</span> <span style="font-family:‘Heiti SC Light‘; color:rgb(0,0,0)">Radio Search</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(39,42,216)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(39,42,216)"><span style="font-family:‘Heiti SC Light‘; color:rgb(0,0,0)"></span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(39,42,216)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(39,42,216)"><span style="font-family:‘Heiti SC Light‘; color:rgb(0,0,0)">note: Broadcast</span> <span style="color:#000000">IP</span> <span style="font-family:‘Heiti SC Light‘; color:rgb(0,0,0)">address is</span> <span style="color:#000000"></span> 255.255.255.255</p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(209,47,27)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(209,47,27)"><span style="color:#703daa">NSString</span> <span style="color:#000000">*str = </span>@ " <span style="font-family:‘Heiti SC Light‘">who is the server?" My</span> IP <span style="font-family:‘Heiti SC Light‘">is:</span>192.168.80.103 "<span style="color:#000000">;</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(61,29,129)"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo; color:rgb(61,29,129)"><span style="color:#703daa">NSData</span> <span style="color:#000000">*data=[str </span>datausingencoding<span style="color:#000000">:</span>nsutf8stringencoding<span style="color:#000000">];</span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:14px; font-family:Menlo">[asyncudpsocket senddata:data tohost:<span style="color:#d12f1b">@ "255.255.255.255"</span> port:<span style="color:#272ad8">9527</span> withtimeout:-<span style="color:#272ad8">1</span> tag: <span style="color:#272ad8">0</span>];</p></p><br><br><br> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Implementation of IOS using socket UDP protocol broadcasting mechanism</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.