Wifi Device to Device Communication problem
I wrote a code in my application to enable Device to Device wifi Communication(transferring only a text/string).The code is same as the Apple's sample Witap Application which is downloaded from Developer.Apple.com.
Its working in my network fine and another networks also.
However its not working in my client site.
I spent time at the Client site to sort out the issue with the Devices not communicating to each other and this is what I found. They in their security setup block peer to peer communication…" and my device communication is identified as peer to peer .
Is there any way to solve this problem Is there anything other than PEER 2 PEER wifi communication which apple supports?
Prototype WIFI applications Working Concepts
There are mainly four classes in WiFi application named as AppController, Picker, BrowserViewController, TCP Server.
When application loads the AppController class will initialize NSInputStraem and NSOutPut Stream.
And also it will call “start” method from TcpServer class to set port number.
After it will call “enableBounjourWithDomain” method from TcpServer class.
The above method call with a parameter开发者_JS百科 called as identifier (it is a common name eg:WiTap) and the sender part is searching devices with this common identifier.
After the execution of this method the sender device can identify our device and able to connect.
Getting Own Device Name
Tcp serverServer delegate “DidEnabledBounjer” will work after the above code execution and it will give the current device name.
Then NSNetservice delegate “didFindService” will work (it work when each service discovered) and retrieve the discovered service name.
After getting the new service name we will check either it is same to our device name which we got from “DidEnabledBounjer” delegate.
if not ,the new service name will add into a NSMutable array named as services.
Then services array bind t o the Table view and we can see the list of discovered device names.
discovering the new devices:
No timer settings for discovering the new devices.
When a new device is connected in the same WiFi net work the “DidFindservice” delegate will trigger(it is a NSNetservice delegate implemented in BrowserViewController class).
DidFindservice will give the new device name .After getting it we will check either it is same to our device name witch we got from “DidEnabledBounjer” delegate.
if not ,the service name will add into a NSMutable array named as services.
Then sort all the discovered ;device names according to the Device name and reload the Table View.
Working after selecting a device name from Table View
After clicking device name on the TableView it will call “didSelectRowAtIndexPath” delegate which is implemented in BrowserViewController class( it is a TableView Class delegate) .
It will select a NetService name from our services array(holds all the discovered services) according to the TableView index and set resultant NSService as Current Service.
Trigger a delegate “didResolveInstance” and it will set the InPutStream and OutPutStream values.
After get ting values for InPutStream and OutPutStream it will call “OpenStream” method to open the input and output Streams.
Finally it release the NSService and Picker objects and ready to send messages with selected devices.
Working of send Button
Call “send “ function from BrowserViewController class with a string parameter .It may be user text input or generated string after speech recognition.
Convert the input string as a uint_8 data type and send it to the receiver device.
Receiver Side Working
When a data came to receiver device the “TcpServerAcceptCallBack” delegate will trigger(implemented in TcpServer Class).
It will call “DidAcceptConnectionForServer” method from BrowserViewControll calss through another TcpServer class delegate named “HandleNewConnectionFromAddress”.
Trigger the “stream handle delegate” which is in “AppController “ class and it will check is there any bites available or not.
If bytes are available convert the uint_8 type data to string and we are displaying the resultant string in receiver text box.
And also loading images and displaying it in Image View from AppBundle using the resultant string.< /p>
In the WiTap source Networking/TCPServer.m the socket's port is set to zero (= the kernel chooses a port number, and it takes a value above 50000). You could change that 0 to e.g. 81, and the nosey security setup will no longer classify you as peer2peer. Any value between 1 and 1023 should work.
You should do basic connectivity tests, to determine what exactly that network is blocking.
Start with a simple ping and move on to UDP and TCP levels. You might find that some form of communication is allowed.
If not, you can try to tell their security guys to accept some form of communication between specific range of ip addresses and/or port numbers and adapt your application accordingly.
精彩评论