How do I communicate between devices connected to a WiFi Access Point? - communication

I have got a couple of phones and another couple of PC's connected to a Wifi access point and need to send and receive messages between either of these, I mean anyone can send a message to anyone and receive a message from anyone.
I am willing to write apps on the phones(Symbian OS, S60 platform) or PC(Windows), but what I can't understand is how do I set up a client or server, since any one of these devices could be a client or server.
If I use sockets do I have to script for ServerSockets and also Sockets on each of these devices? Can I use the HTTP protocol?
Alternatively any standard protocol that I could use to implement this?

You would broadcast UDP packets which would arrive at every device on the Wifi network. You would have to invent your own protocol to decide on the identity of each device, since you wouldn't be able to easily infer the IP addresses of your network devices. Without writing an election algorithm you would find it difficult to use a client/server architecture, so just use point-to-point (P2P).
Google for UDP broadcasts and read the relevant RFCs at ietf.org.

It seems like you're looking for pretty typical peer-to-peer communication over IP. I suppose other requirements will dictate which transport you use (HTTP, raw sockets, etc), but yes: Each node will be both a client and a server. You could possibly use MDNS (http://www.multicastdns.org/) to help the nodes find eachother in an ad-hoc manner.

Related

Internet connection problem from different network for NodeMCU ESP8266 which I am using for IOT home automation

Would anyone like to help me with this problem please?
how to connect/control Nodemcu esp8266 wi-fi module from different network for control iot devices from outside of any home/ house?
Internet connection problem from different network for NodeMCU ESP8266 which I am using for IOT home automation.
Actually, in case of an class project, I have used some code (also coppied some code and took help from some website) from internet and also used Blynk for controll my ESP8266.
But not i want to make a personal app by which app I can control my devices outside from my home.
I have already connected with my WI-FI router with my home network!!
It worked well,
But i don't know how to do the same thing from different netwrok.
If possible I think anyone can help me....
Thank you.
To everyone.
This has been answered in greater detail on both the Arduino and Internet of Things StackExchange sites. In summary:
For safety, it is difficult to start a connection to a device on another local network. Devices on WiFi networks are protected from the Internet by a firewall, which is normally configured to return responses to requests sent by the devices, but block all unsolicited messages. Even if the firewall allows an incoming connection on a given port, "port forwarding" or other custom configurations are needed for unexpected messages to reach one of the multiple devices on the network (the devices usually share the same public IP address of the network and external systems' messages cannot reach the right local address without forwarding by the router).
Any device exposed to unsolicited requests like this is at risk of being attacked and can pose a risk to other systems on the network. It is thus safer to leave the firewall the same and instead make the device subscribe to an external webserver, which acts as a mailbox for incoming messages. Then, you can send requests to the server from anything with an internet connection, and the server will store them and relay them to the ESP8266 whenever the ESP asks. MQTT protocol using a server-side broker program like Mosquitto and a client like PubSubClient on your ESP8266 could work for this sort of publish-subscribe model, and MQTT tutorials and explanations are available both on both tool sites and Stack sites.
You can use Arduino IDE to program ESP8266 device.
https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/
After installing ESP8266 in Arduino IDE. You need to connect ESP8266 with WiFi router(which have internet connected). Once your device is connected with a WiFi router. you can MQTT protocol to communicate with the server. You can use the following library in Arduino to implement MQTT client in ESP8266. ESP8266 is used to send and receive data from a different network. ESP8266 is subscribed to a particular topic. You can publish data to that topic from different MQTT client.
https://github.com/Imroy/pubsubclient
Use the Following link to get more familiar with MQTT protocol
https://www.hivemq.com/blog/mqtt-essentials-part-1-introducing-mqtt
You can use MQTTfx desktop application to send and receive data from NodeMcu(ESP8266).
MQTT basic diagram for understanding

Scanning for network devices

I want to scan for all devices in the local network. Then I want to further check if the discovered devices respond on a specific port, say #4000 for example. All that should happen on an iPad preferably using Swift (version 3).
Should I use a library for that job?
This document didn't help me and sadly I cannot find useful information on the internet.
Edit: I want to know how can you implement this in Swift/iOS libraries. Are there any examples, libraries, core classes where I should start?
I think I may know what you are trying to ask. Your device sees the router, but doesn't know who is connected.
Read about multicast IP and broadcast IP, which is usually the highest IP address in your subnet.
Example: 192.168.1.255
As example, you make all devices listen on broadcast/multicast IP. To discover, you send a UDP message to that IP. Your router, if not configured otherwise, will forward that to the other devices.
This message can be something like "I am Mr. John, Reply to me at this Port".
That is the general idea

How to link/pair HTML 5 with a hardware device?

I have two entities which I would like to be able to start a communication:
Hardware Device Using Atmel ATSAMS70 and WINC1500 Wifi Module
HTML 5 App
The idea to have a HTML 5 app is to be able to communicate easily with most of the commercial devices like: Windows computers, Android Phones, Mac OSX computer and iOS devices. Apart from that, I would avoid working with native code at all.
Currently, they can talk with each other using WebSockets but somehow the IP address of the custom board has to be known from HTML 5 to initiate the communication.
In order to do this, I can think of 3 options:
Using WebRTC I can get the local IP address of the browser and then I could do a scan of the local devices considering a 255.255.255.0 network mask.
Have an external server that the hardware device can send its local address which will be later retrieved by HTML 5.
Using Bonjour or some sort of device discovery service between the board and HTML5.
I could not find a way to achieve #3 but #2 seems feasible to me. #1 is what I am doing now, but WebRTC is currently not supported on iOS.
So, is there any other better possibility to achieve this communication?
You don't mention how the WINC1500 unit is being connected to the network but presumably this is in STA mode (acting as a wifi station rather than becoming a software access point or part of an ad-hoc network) and is being provided with its IP details through an existing access point?
Ordinarily I'd suggest that once connected, the device ought to start indicating its availability on the network via a regular UDP broadcast on a specific port but my (admittedly limited) understanding of WebSockets it is that it creates TCP connections. The only implementation of Bonjour that I've seen uses UDP messaging too, that may be why you've had trouble with your third approach.
Your second approach seems more likely to work well. A server at a known (or discoverable) IP on the local network which allows the Atmel device to register itself (and its IP address) and also allows other applications (your HTML 5 WebSockets applications) to request that connection information to allow them to create the WebSocket TCP connections they need.
I suppose that doesn't really answer your question as to "Is there a better way?", other than to say "Not that I can think of, your second approach looks good to me...". Sorry! Sounds like a very interesting project, overall,

Bulletproof HTTP Monitor for iOS

I'm using Charles Proxy and Wireshark to monitor http(s) traffic from various iOS apps I'm using on my iPhone. These apps require me to set the HTTP Proxy under the iOS Wifi settings (let's call these the Proxy Settings).
My business needs to see ALL URL's that are being called from my phone. From all apps. All URL's, not some of them.
Now Charles and Wireshark both work fine and I can see a ton of traffic coming from my phone.
However, I can't help but wonder whether I might be missing some HTTP calls. Maybe calls that don't use the Cocoa Core Foundation libraries as the basis for their networking.
For instance, I could write my own HTTP library out of TCP/IP and these would bypass the Proxy Settings.
So my question is: what is the likelihood that some apps are using custom-rolled HTTP libraries and side-stepping my Proxy Settings. Or worse, they're using raw TCP/IP to communicate with a server. I know it's possible, but do any APIs work this way? Does anyone do it?
I found the answer: Use mitmproxy in transparent mode. proxy is not used. harder to setup because it needs work on the router, but it reliably captures every packet on port 80 and 443 regardless of proxy settings.
Assuming that you are able to keep your device tethered, then you may be able to use the pcap service to monitor all traffic. According to the following paper (2014) the pcap service is running on every iOS device:
"Identifying back doors, attack points, and surveillance mechanisms in iOS devices"
You should be able to connect to it via usbmuxd. I'm not sure whether there is a pre-rolled client for the pcap service. There is a list of services supported by libimobiledevice here. Pcap is not on that list.
Alternatively, you can use wireshark to capture all traffic on your wifi network.

Which connection class type should we use when connecting to a server to stream an audio file?

I need to connect to a server where resides an mp3 file and stream it. If I am not using rtsp connection what do u suggest me to use? Can we use rstp in this case?
Is it fine to use a http connection? I used that but it seems to take a long time to actually connect to that server. Can I improve the performance by using any other connection class?
Thanks
HTTP over Wi-Fi, Direct TCP, or WAP2 is the best connection method to use for streaming audio if you want to reduce the number of intermediate proxies and carrier networks. Transports such as BES and BIS go through third-party infrastructure (enterprise in the base of BES and RIM in the base of BIS), which adds another point of failure in the path. Not only that, but I have asked RIM employees directly what their thoughts were on streaming media over BIS and their short but sweet response is "don't". They don't want the extra traffic going over their network. I have heard from the BlackBerry forums that large HTTP transfers aren't very reliable over BIS, anyways. In a similar way, BES admins probably don't like apps that try to stream a lot of media through their servers as well.
That leaves Wi-Fi, WAP2 and Direct TCP. Wi-Fi is a no-brainer for devices that have it (and users who are connected) but remember most CDMA devices don't have Wi-Fi so only a small percentage of users may have it. WAP2 is nice in that it doesn't require manual "APN" configuration, however in my experience not all carriers are set up for WAP2. So you may want to try that first and if it doesn't work (i.e. no WAP2 service records or connections over WAP2 fail), use Direct TCP.

Resources