How to make an instant messenger system in current internet settings? - server

First I want to define my question:
1, I am talking about computer program doing the IM, not mobile app. The program should be working in every home, or office environment.
2, Right now all (or most) home computers are behind a router, protected by ISP's security policy. It is not like 20 years ago, when a computer connects to an adapter, it gets a universal IP, as good as Microsoft.com and whitehouse.gov. 10 years ago, you can advise user to do port forwarding, or use UPnP to stealthily perform the port forwarding task. But now in the name of security, ISP is taking port forwarding out from the ISP-managed router (xfinity is doing that, as far as I know).
I know how to do IM in LAN setting, or the universal IP setting, that you get the IP of the friend, establish connection using TCP or UDP, then transfer information. Now when all computers are behind the routers, what is the feasible way / popular way / right way to do IM again? Using a central server to transfer information, by establishing connections of UserA-Server and UserB-Server? I know it would work, but not very "instant", in my humble opinion.
Please advise, thanks.

Upnp and NAT-PMP can still work, it will map a external port like punchhole. The problem is that our external IP may not be sure. So if you want to send IM, there are two choices, DHT or Central Controller.
I suggest you to use DHT and a central server using ICE structure, if DHT can work then it is ok, or we can use the central server to do the UDP/TCP traversal. In some circumstances like symmetric NAT, the server need to do relay, but in others, it just start the connection and then it is a p2p connection without server.

Related

When 2 computer interact over a network connection then first they have to make a socket connection?

Please answers in yes or no. This will solve my doubt.
1. Is a post/get request sent from computer-1 to Computer-2 then first they have to make a socket connection?
2. When 2 computers connect with ssh then first they have to make a socket connection , then only then can talk to each other ?
The examples you give involve network connections and sockets are a common abstraction used when communicating over modern computer networks; however, other abstractions could be used. This is what Damien_The_Unbeliever is saying in the comments. For example, you could ask whether for loops are the only way to iterate over an array. The answer is the same: for loops are a common abstraction to loop over elements of an array, but there are other equivalent (in a machine-code sense) methods of doing so using other abstractions.
More fundamentally, computers can communicate with each other without using networks at all. You could have computers communicate over an interface consisting of webcams and monitors; sending is accomplished by putting something on the screen and receiving is accomplished by receiving the video feed. You could do the same with microphones and speakers. You could do the same with robotic arms, keyboards and mice. Two computers can communicate with each other using a human courier; my work and home computers do it regularly! Computers could write letters and mail them, deliver them or use carrier pigeons to send them to other computers designed to accept information in those formats.
Please answers in yes or no. This will solve my doubt.
[ok]
Is a post/get request sent from computer-1 to Computer-2 then first they have to make a socket connection?
In this case, Yes, but if request is going from browser then it do for you.You can see thr url for get and post have the port number in them. If not mentioned the default port is 80, in general. For example If you use WebSphere Application Server, the default port is 9081 or 80 if IBM HTTP Server is configured.
When 2 computers connect with ssh then first they have to make a socket connection , then only then can talk to each other ?
In this Case, again Yes, the port is 22 in ssh

How exactly do p2p networks connect?

If I establish a connection with a friend on Skype, the audio and video data does not go through Microsoft but directly. I also have a p2p client X that does a similar thing. I do not fully understand how this happens internally. How does a machine establish the connection with the other if there is no direct identifier such as a public IP address? Multiple computers in the same network can each do p2p or Skype calls at the same time.
I have been wondering about this for a week because I want to connect two Nodes with each other (like a socket server/client). Can you point me in the right direction?
If two clients want to connect, but neither knows the address of the other, some sort of intermediary that they both know has to be in place to help set up the connection. They both contact the intermediary with the desire to connect, the intermediary tells them both what the others direct address is, and the connection can be set up directly.
Sometimes (read: always) one or both machines share a public IP with others behind NAT, and NAT traversal techniques are needed to establish end-to-end connectivity, usually some form of ICE or SIP.

Message Computer Over IP/Port

I'm having some trouble with this, and have a hard time explaining the problem in words, but I will do the best I can.
I would like to send a simple message to a computer from a different computer. Nothing fancy. I have done some research, and a lot of sources say to create a script that accesses the built-in MSG.EXE function in Windows (I am currently on Windows 10) however, this only seems to work on machines connected to LAN.
From what I have gathered, I would need to create a website that handles the requests: get message from Computer A and send it to Computer B. Could I do this (In Powershell or VBS) without having to make a site specifically for it?
What I want:
I want Computer A to send a plain-text message to Computer B. Preferably, when the message is successfully sent a message box will appear that says "From: (whomever) and the message. Using MSG.EXE did what I wanted it to do, however it only worked with LAN-connected devices. Could I make this work with static IP? If so, how?
Additional Information:
The two computers are not on a LAN, but are connected to the Internet.
Computer A (the sender) and Computer B (the receiver) each have a static IP address, however that can obviously change.
Ports are available in each computer.
I have a Raspberry Pi that could act as a server "middle man" should that be required.
To be very clear: There are a lot of posts that talk about sending messages over LAN. I am NOT trying to send a message over LAN. Any help would be appreciated.
You're being quite vague in why you want it and what you want it to do; the main problem is that home internet connections are built for things to connect out, and nothing to connect in.
Fixes:
Port forwarding where you say "incoming connections go to this or that computer.
Building a service where both sides "connect out", i.e. you have a website hosted somewhere out on the internet. One computer connects out to send the message, the other connects out to check for messages.
Outside that, the next problem is knowing where on the internet to connect to.
Fixes:
Hard code the end points. Static IPs are good for this because the definition of a static IP is that it's an address which doesn't change. Mysteriously, you have static IPs which can change and you consider that 'obvious'. (??)
DNS where you register a domain, and the computers look at a domain name for where to connect. You update DNS with the current IP.
DNS where you use a free DNS service on someone else's name and your service listener updates that as its IP changes.
And after that, most people's computers/laptops/phones are switched off or in low power sleep mode most of the time, and their internet connections are comparatively unreliable, so any random message probably won't be answered.
Fixes:
Use a serious website service
Run an always-on computer to be that service
Deal with it being offline and messages being flakey
Use a store-and-forward system like email, which queues and retries, like e-mail and instant messengers do
get message from Computer A and send it to Computer B. Could I do this (In Powershell or VBS) without having to make a site specifically for it?
Yes. Quick answer: pick a port, configure site B's modem/router to forward the port to computer B. Open the port on computer B's firewall. Write some kind of TCP socket listener on Computer B, and the sender on Computer A, connecting to the public IP address of site B.
Long answer: then enjoy writing your own messaging protocol, error handling, message authentication, etc.
Alternative: do the same but going to your rPi. Have it listening. Not in powershell (sadly) or vbscript (luckily), and have it serve the messages up by HTTP/JSON, both computers invoke-webrequest or invoke-restmethod and post/get them with regular polling.

Connect sockets directly after introduction through server

I'm looking for the name of a protocol and example code that permits handing off IP/port connections to establish unmediated P2P after introduction through a server.
Simple example:
You and I both start chat programs that connect to chatintroduce.com (fictional server). I send you a "Hi! Wanna chat?" message. It doesn't get sent. Instead my chat program tells chatintroduce to send your chat program a request for connection. You respond to a prompt and your chat program tells chatintroduce to broker the connection. Chatintroduce establishes an initial two-way connection between us. Now, this final step is important, chatintroduce releases control and our two chat programs now talk directly to each other without any traffic through chatintroduce.
In other words, I construct packets which have your IP address and you receive them without interference from firewalls, NATs or any other technologies. In other words, true peer-to-peer connection independent of intermediate server.
I need to know what search terms to use to find appropriate technology. An RFC name would suffice. I've been searching for days without success.
I think what you are looking for is TCP/UDP hole punching which typically coordinates the P2P connection using a STUN server to determine the "capabilities" of the firewalls (e.g. is it a full cone nat? symmetric?).
https://en.wikipedia.org/wiki/Hole_punching_(networking)
We employed this at a company I worked for to create a kind of BitTorrent that could circumvent firewalls for streaming video between two peers.
Note that sometimes it is NOT possible to establish a connection without the intermediary.
What you are looking for is ICE protocol. RFC 5245. This protocol is used for connecting two peers through NAT traversal. There are some open source libraries and also some proprietary libraries for this. You can search google with ICE implementation.
You will also need to read about some additional protocols. These are used with ICE protocol. They are STUN and TURN.
For some cases you can't make P2P call 100% time. You will have to use a relay server. Like if the NAT combination of two peers are Symmetric vs Symmetric/PRC. That relay server is called TURN server.
Some technique like Port forwarding and TCP/UDP hole punching will help you to increase P2P rates.
See this answer for more information about which combination of NAT will require a relay server and which don't.
Thank you. I will be looking further into ICE, STUN, TURN, and hole-punching.
I also found n2n which looks like almost exactly what I wanted.
https://github.com/meyerd/n2n
http://xmodulo.com/configure-peer-to-peer-vpn-linux.html
With n2n, one makes a VPN with a super node that all other edge nodes know.
But once the introductions are made, the super node can be absent.
This was exactly what I wanted. I hope it works across platforms (linux, MacOS, Windows).
Again, I am still researching before implementation, so your advice was very important to me.
Thank you.
Use PJNATH. Its open source.
http://www.pjsip.org/pjnath/docs/html/
There is not much open source on NAT Traversal. As far as I know PJNATH is good.
For server you can use Google's Open source STUN and TURN server.

Writing a simple P2P chat application

This is my first experience with P2P and i need some help regarding the design.
I am developing a simple messenger application. I have a directory server on which every user authenticates and announces an open port on which every user is reachable. The directory server maintains the users and the ports and I can query the directory server for any specific user. This part is done. The second part is the chat which i think should be P2P. I can start a chat as well as I can be end point of a chat (client as well as server)
What is confusing me is how do I deal with P2P? Do I create two different sockets? One on which I am listening for TCP requests for incoming connections and another one from which I would send TCP requests to start chat.
In this case do I need 3 sockets, one to talk with server and two for P2P?
If you want to go P2P, you'd better use a framework, such as JXTA for example if you are coding in Java. Creating sockets may not be enough by itself, because there are more complicated issues you need to deal with such as NAT traversal if you are operating beyond your LAN.
It seems like you have a central peer (some of server). If it has a public IP address, then you could implement a TURN-like architecture (peers communicate via this central peer). If you want direct connection between peers, you are looking a STUN solutions, but you still need a central peer to facilitate the communication.
TCP Stun is not easy. UDP is not very complicated, you just need to punch a hole in your NAT. Now, keep in mind that NAT traversal is not always possible (it depends of the NAT itself). In this case, the backup solution in a STUN one.