Wi-Fi device issue for device

I wrote code in my application to enable Device to Device wifi Communication (text / line only). The code is the same as the Apple Witap sample that is downloaded from Developer.Apple.com.

It works on my network and on other networks.

However, it does not work on my client site.

I spent time on the Client website to deal with the problem when the Devices did not exchange with each other, and this is what I found. They, in their security settings block, accept peer-to-peer communication ... ", and my connection with the device is identified as peer-to-peer.

Is there a way to solve this problem Is there anything else besides the PEER 2 PEER wifi connection that the apple supports?

WIFI Application Prototypes Working Concepts


There are basically four classes in a WiFi application called AppController, Picker, BrowserViewController, TCP Server.

When the application loads, the AppController class initializes the NSInputStraem and NSOutPut stream.

And also he will call the "start" method from the TcpServer class to set the port number.

After calling the enableBounjourWithDomain method from the TcpServer class.

The above method call with a parameter called an identifier (this is a common name, for example: WiTap), and part of the sender is the search devices with this common identifier.

After executing this method, the sending device can identify our device and connect.

Getting the name of your own device


The Tcp serverServer "DidEnabledBounjer" transmitter will work after the above code has been executed and will display the current device name.

Then the NSNetservice "didFindService" delegate will work (it works when each service is detected) and retrieves the discovered service name.

After receiving the new service name, we will check to see if this matches our device name, which we received from the DidEnabledBounjer delegate.

If not, the new service name will be added to the NSMutable array, called services.

Then the array of services is attached to the table view, and we can see the list of detected device names.

discovery of new devices:


No timer settings to detect new devices.

When a new device is connected to the same Wi-Fi network, the “DidFindservice” delegate will start (this is the NSNetservice delegate implemented in the BrowserViewController class).

DidFindservice will provide a new device name. After receiving it, we will check either the same as our device name, which we received from the DidEnabledBounjer delegate.

If not, the service name will be added to the NSMutable array called services.

Then sort all the detected device names according to the device name and reload the table view.

Work after selecting a device name from the table view


After clicking the device name in the TableView, it will call the delegate "didSelectRowAtIndexPath", which is implemented in the BrowserViewController class (this is a delegate of the TableView class).

It will select the NetService name from our array of services (contains all the discovered services) in accordance with the TableView index and set the resulting NSService as the current service.

Run the delegate "didResolveInstance" and it will set the values ​​InPutStream and OutPutStream.

After receiving the values ​​for InPutStream and OutPutStream, it will call the "OpenStream" method to open the input and output streams.

Finally, it frees up the NSService and Picker objects and is ready to send messages with the selected devices.

Submit Button Operation


Call the send function from the BrowserViewController class with a string parameter. This can be user text input or a generated string after speech recognition.

Convert the input string as uint_8 data type and send it to the destination device.

Receiver side work


When data arrives at the destination device, the "TcpServerAcceptCallBack" delegate will be launched (implemented in the TcpServer class).

He will call the “DidAcceptConnectionForServer” method from the craws BrowserViewControll through another TcpServer class delegate named “HandleNewConnectionFromAddress”.

Run the "thread descriptor delegate", which is in the "AppController" class, and it checks for available bites or not.

If bytes are available, convert data of type uint_8 to a string, and we will display the resulting string in the recipient's text box.

You can also upload images and display them in Image View from the AppBundle using the resulting row. </p>

+6
source share
2 answers

In the WiTap Networking / TCPServer.m source, the socket port is set to zero (= the kernel selects the port number and it takes a value above 50,000). You can change this value to 0, for example. 81, and the new security setting will no longer classify you as peer2peer. Any value from 1 to 1023 should work.

+1
source

You must perform basic connection tests to determine what exactly this network is blocking.

Start with a simple ping and go to the UDP and TCP layers. You may find that some form of communication is allowed.

Otherwise, you can ask your security guys to take some form of communication between a certain range of ip addresses and / or port numbers and adapt your application accordingly.

0
source

Source: https://habr.com/ru/post/897389/


All Articles