I'm asking is this is possible to connect directly both application from the internet without using the public ip address as the tunnel or connector.
I used this code to connect each computer from different network connections.
The client uploading the file to send to public ip address using FTP
function UploadToFtp(serverName, userid, password, fileName: string): LongBool;
var
hNet, hCon: HINTERNET;
begin
Result := False;
hNet := InternetOpen('myagent', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
if Assigned(hNet) then
begin
hCon := InternetConnect(hNet, PChar(servername),
INTERNET_DEFAULT_FTP_PORT, PChar(userid), PChar(password),
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0
);
if Assigned(hCon) then
begin
Result := FtpPutFile(hCon, PChar(fileName),
PChar(ExtractFileName(fileName)), FTP_TRANSFER_TYPE_ASCII, 0
);
InternetCloseHandle(hCon);
end else ShowMessage(SysErrorMessage(GetLastError));
InternetCloseHandle(hNet);
end else ShowMessage(SysErrorMessage(GetLastError));
end;
The Server to collect information from public ip address.
function DownLoadFileFromFTP(server, username, password, localfile, remotefile: string; port: word = 21): boolean;
var
hopen, hconnect: HINTERNET;
good:boolean;
begin
hopen := InternetOpen('myagent', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
hconnect := InternetConnect(hopen, pchar(server), port, pchar(username), pchar(password), INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
good := FtpGetFile(hconnect, pchar(remotefile), pchar(localfile), false, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
InternetCloseHandle(hconnect);
Result := good;
end;
> Is there a way to directly connect each computer without using the FTP, I meant the socket? or any means to connect directly between the two computers from different network?
Is it using a (web-service from Delphi) web component on each computer? I don't really know what to do, or any options to connect each directly.
thanks
AS. Making this answer so it would be able to structure text.
You have a lot of means to communicate in Delphi
That may suit you to work in flat LAN environment, making applications like https://sourceforge.net/projects/dreamchat/
However if you want to go into Internet (like FTP tags suggests) you'd better switch your strategy.
The problem with p2p includes
_1. finding each other:
1a: on one pre-defined meeting point (server) like Skype
1b: on user-specified meeting point (server) like E-Donkey2000 or BitTorrent
1c: or using free scan of the internet until finding someone Gnutella/G2 networks or server-less DHT-based BitTorrents.
_2. checking that the other peer worth your trust. For file exchange P2P that is warranted by file hashes (who cares of the peer is fair or malicious while he uploads correct content). For computer games usually some AntiCheat tools are used to a mixed success.
_2a ensuring that all the intermediate peers would not be able to eavesdrop on your data (or that you don't care if they do) and that they cannot tamper the data intentionally or corrupt it due to some random error, without that fact be notices by your program and repeated transmission be requested.
_3. ensuring that bi-directional communication can be established, and that is
_3a. getting some publicly-visible IP of yourself or erzats of it
_3b. communicating this address to unknown-yet peer
_3c. ensuring that that address may actually be used to communicate, and that means pinholling a NAT or several nested NATs using UDP, NatPMP, UPnP and other techniques ad hoc, testing if any of them can or can not work with a given NAT. Maybe IPv6/TEREDO can be used for this meen in some circumstances.
_3d. degrading gracefully to some retranslating mirror-server in case than none of the peers could establish working "direct" public address to it.
All of those problems have their one cans of worms and you cannot get the,m solved at once. You would have to deal with them one by one, including asking questions and searching wikipedia oveview and tutorials.
My best advice to novice would be not trying to do it but to dump NIH-syndrome and re-use some already established networks for it. This may include
XMPP aka Jabber. Many people today have account on Google Mail (and GTalk) or Yandex Mail (and Yandex online) and such. Your application may use XMPP library to connect to those accounts and use them for realtime XML-based communication. It is nor P2P in strict sense, but you need the communication, not the rigid following to terms.
BitTorrent: uTorrent recently told about uTorrent DNA - the SDK to use running uTorrent applications as a mesh networks to propagate any custom data.
TOR and I2P would probably be too slow, as their emphasis is not on fast communications, yet they do exist.
Gaming-oriented services like Hamachi.cc
Remote-controlled helpdesk services like TightVNC or TeamViewer, that usually can establish private VPN, but would require installing or renting retranslating mirror server.
and so on - just do your search. There are already established networks that for years have dealt with those challenges and teething problems and you'd better reuse their experience that wasting time and effort to develop your own inferior (and for yeas to come it would be inferior) solution