I am trying to create a dart/flutter application that is capable of sending and receiving data with sockets over the internet (WAN), without an intermediary, peer-to-peer.
I may have managed to create this on the local network (LAN), through the wifi I can transfer data, but how to transfer data on the global network?
It seems to me that I need to open a port, but how can I do this on dart? Or is there another way.
Briefly - Chat between 2 directly connected users wherever they are.
I tried to connect to an external IP address, but it does not work, I searched and asked people, but they do not know.
Related
I want to create a data streaming server, and I need a solution, cuz I can't understand what I should to use.
Okay, I have a central home server, which contains infos about temperature, light, motion sensors, music on my central home sound bus and more. And I want to create solution like:
Server continuously sends the data to the local network via port.
And at any time I have an opportunities to connect. For e.g. I connect to 192.168.1.2:1234 and immediately start to listening all information. I can do it from any clients and at the same time. And the server may not even know about connections. It only sends the data to the local network via port, and nothing more.
UPD:
I used TCP protocol to exchange the data between server and clients, but it wasn't a good solution, cuz it's not suit to my described idea.
I need to make TCP based decentralised chat app for local network. By decentralised I mean there is no central server. Each entity on a network should have server/client architecture. When app starts it should check which user is online ( already running the app ). My question is how can i check that? Can i do it by trying to connect via connect() function from socket library? I'm new to programming, especially socket programing, so if it's a dumb question sorry in advance.
You should definitely study how other decentralized applications do this. There are lots of techniques.
Each instance of the application should, as part of its server functionality, track the addresses of other instances of the application. Each instance should, as part of its client functionality, keep track of a few instances it can connect to. Prefer instances that have been around for a long time.
The software should include a list of servers that have been running for a long time and are expected to typically be available. You may wish to include a fallback method such DNS, maintained by anyone willing to keep a list of well-known servers offering access through a well-known port. The fallback method can also be IRC or HTTP.
If you want to stay decentralized, you might want to try multicasting or broadcasting a request packet to all hosts on the network to discover other instances of your chat application.
Something similar has been implemented in Pidgin, named Bonjour. It works quite nicely and provides chatting capabilities on a local network. More specifically, it is defined as a Serverless Messaging part of XMPP.
If you are looking for code examples, have a look at one of my projects where I use multicast to discover hosts on the local network that provide a specific service: Headers and implementation.
This Morning I Booted my Computer and Had multiple applications needing an update. While I was waiting for the applications to update, a question came to mind which I thought I'd ask in here.
The question is How does each application known which internet data being retrieved is theirs?
The applications don't even care about it, they let the Kernel sort out that information.
When an application establishes a connection with a remote computer, the Kernel assigns that application a local port, which is a number among 0-65535. This port on the receiving end can either be requested by the application or the kernel will assign a random port. Generally there is only one application per port, however it is possible for multiple applications to receive the same data, though this is rare.
When a packet is received by the network interface, the kernel will sort the packet by its destination port. There will be a table in the kernel mapping ports to processes, and each application will receive the relevant data without caring about any other possible data that could be coming in the computer.
If you are a programmer, you can learn about all this stuff by reading about socket programming:
http://en.wikipedia.org/wiki/Network_socket
is a good place to start. You can also google "socket programming" with your preferred programming language to get an idea of how this is set up on the programming end.
I've read tons of questions about this all over the web, and can't seem to find a solid answer. If I have an iPhone that's running on cellular data and another iOS device on wifi (in two separate locations), is it possible for them to send data to each other directly without sending it first to a web server, then retrieving it? Are the only options sending and receiving from a server/Apple's iCloud? What if I knew the devices' ip addresses? Note that the iPhone has WiFi disabled.
I'm not looking to put this in the app store, it is for personal use. I know NSNotificationCenter isn't an option.
Using the gamekit framework you can send data between two iOS devices. It is easy to implement. Other than that I don't think there is any other way to send data between two iOS devices.
Actually, it IS possible. You may want to google for something called "UDP hole punching" or "TCP hole punching".
The main approach in short: Assuming you got something like a relay server, that is some server in the internet that is publicly addressable from every private LAN that is connected to the www. No you have your two clients A and B in (different) private LANs, with some Network address translation (NAT) going on, that want to establish a peer to peer connection.
First of all both will tell the server their IP address and the port they have in their own LAN. In the UDP or TCP packet, the server will find the public address and port of the device (or the NAT (router)). So the server knows the private and the public IP address as well as the ports.
If now A wants to communicate with B, it asks the server for help. The server will send a message to B that A wants to communicate with her telling her A's public and private IP and port. A gets back B's public and private information and port.
Now here is where the magic happens. Both clients now send packets out to establish a connection simultaneously to the private and public addresses of the other party and thus punching a whole in their NATs such that incoming connections will not be blocked. Even if one party's connection establishing packets will arrive before this whole is created, the other's packets will get through to such that a connection can be created.
Beware of some NATs that scan the data for IP addresses and translate them as well, but if you encrypt your data or change the appearance of the address (complement, ...) you will be fine.
Now the master question, how can the server communicate with one of the clients without an active connection. Well in this case you can use "connection reversal" and apple's "push notifications". Use the "push notifications" (pn) to tell a client behind a NAT that there is something of interest going on and that it should contact the server. Once it has done that the connection is active and can be used in the previous described fashion.
I hope this helps some people that get to this problem although the post is quite old!
You can only use direct IP address communications if the IP address are publicly reachable IP addresses accessible over the internet, and they are static (enough) so that they are not changing on you regularly as devices get assigned to addresses dynamically. In many (most) cases, that won't be true because your devices will be assigned their IP address dynamically and those addresses are frequently going to be self-assigned IP addresses that aren't publicly addressable.
As others have commented, using Apple-provided mechanisms like iCloud are probably the easiest options. If that's not something you'd like to entertain, there are probably ways to make use of a dynamic DNS service like DynDNS to manage the actual IP addresses of your devices. With something like that you might be able to use a direct IP connection between devices based on a named DNS lookup. You'd probably have to jump through some hoops to make that happen though and I'm not sure you'd want to go to that extent.
I think that Bluetooth would be a good option for you
I am creating a class which communicates with remote server. Currently my device (iPhone 4) is having connectivity via wifi and local network cellular. By default it uses wifi. It works fine in both the cases.
However when I switch from wifi to cell service, it hits error delegate. I want keep communication on going even when connectivity is changed.
Is it possible? How?
Thanks,
I don't expect it is possible. Having switched networks, you've probably also switched IP addresses. Connections are defined by the IP addresses of the end points (as well as protocol and protocol-specific data such as port numbers). So, you can't maintain a connection when the IP address changes. You must cleanup and dispose of the broken connection and open a new one.
If the high-level protocol you're using, such as FTP or HTTP, allows it, you can try resuming the data transfer at the point it was interrupted. For example, if downloading a file, you may be able to resume the download at the file position of the last data you received.