title: P2P Connection using Delphi
body: <p>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.</p>
  
  <p>I used this code to connect each computer from different network connections.</p>
  
  <blockquote>
    <blockquote>
      <p>The client uploading the file to send to public ip address using FTP</p>
    </blockquote>
  </blockquote>
  
  <pre><code>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;
  </code></pre>
  
  <blockquote>
    <blockquote>
      <p>The Server to collect information from public ip address.</p>
    </blockquote>
  </blockquote>
  
  <pre><code>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;
  </code></pre>
  
  <blockquote>
    <p>>
    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?</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>thanks</p>