Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 258
humblePilgrim Avatar asked Sep 15 '11 13:09

humblePilgrim


People also ask

Why is my Wi-Fi not connecting to other devices?

It's probably just a momentary network issue. Try turning off the Wi-Fi on your device, then re-enabling it. If that doesn't work, do the same with your router by unplugging it and then plugging it back in 30 seconds later.

How does Wi-Fi communicate between devices?

Wi-Fi uses radio waves to transmit information between your device and a router via frequencies. Two radio-wave frequencies can be used, depending on the amount of data being sent: 2.4 gigahertz and 5 gigahertz.

CAN devices on same Wi-Fi communicate?

Generally, just because you use the same WiFi access point, it doesn't mean you'll be able to communicate with them. Your ability to communicate with them is largely dependent on what operating system the other users use and what communication tools they have installed/available.


1 Answers

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.

like image 69
ott-- Avatar answered Sep 28 '22 00:09

ott--