Title: Send text messages between two computers through internet with delphi?
Tags: delphi;p2p
Question: I want to write a app which will run on different computers and need all of then to communicate with each other like "utorrent" (peer to peer). This app only will send text messages. 

How can I do this? I mean sending one message to remote computer on the internet? 

I have a website and every app at start can send some information to it and find information of other apps on other computers (with PHP) but I do not know how address one computer through internet and send the data directly to that. I can find the ip address with PHP but it is the ip address of router (ISP).

How a message reaches a computer? I'm wondering about addressing every computer?

My brain really stuck here, I really appreciate any help. Thanks.  


Here is the accepted answer: In a peer-to-peer network there's no centralized server for transmitting the data from one client to another, in this case the clients must be able to act as both the server and client. This means that either you'll have to be using UPnP like most modern torrent clients, which handles port forwarding in the router, or you'll have to manually forward a port to the computer in the router.

A centralized server (like a torrent tracker) is usually used to make the clients aware of each other's existence and tell them where to connect. This is where your PHP script comes in, though PHP might not offer the most effective way of doing this, assuming you're using it in combination with a webserver to serve the data though the http protocol.

As for actual text communication, you could use the Indy socket library for that. I found this example, basically which shows how to do it: http://www.ciuly.com/delphi/indy/indy-10-client-server-basic-demo/

Comment for this answer: as I said, either you have to manually forward the port or you have to use UPnP to have the router to it for you. This appears to be an Indy compatible library to do that: http://www.whitebear.ch/upnp.htm
Comment for this answer: I know these things. My question was that how forward a port in the router to the computer where my app is? We have not acsses the router. think about utorrent. It easly forwards data through every router in the internet to the peer. I do not understant that what is the exact address of a computer in the internet witch I have to enter it on Indy to comunicate.
Comment for this answer: How router will know that it have to forwards data of a port (for example 5689) to a computer witch my app is?
Comment for this answer: Those examples did not help much


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:06/02/12', 'FavoriteCount': 2.0, 'PostTypeId': 1, 'Tags': '<delphi><p2p>', 'Title': 'Send text messages between two computers through internet with delphi?', 'ViewCount': 3830, 'id': 10863756, 'user_AboutMe': "<p>I'm developer of android, windows ce, windows mobile, windows (C#.net and delphi), web designer with PHP and javascript. I have my own layered structure for designing applications. I programed some big projects only by myself for different offices and companies in Iran. I also develop projects for companies in Turkey and Iraq.</p>\n", 'user_AccountId': 1356922.0, 'user_DisplayName': 'hamid', 'user_Reputation': 824.0, 'user_Views': 159.0, 'user_id': 1295141.0}}