Delphi - Bridge two TCP ports
<p>Scenario:</p>

<p>PC1: (IP: 192.168.1.100)
Delphi application running 2 listenener at port 5555 and at port 80
Problem:
Application set up a both-way communication link beteeen port 80 and 5555.</p>

<p>PC2: (IP: 192.168.1.200)
Delphi application running a webservice listening at port 8888.
Problem:
Application makes a connection to PC1 at port 5555 and after that sets up a both-way communication link between local port 8888 and the connection to PC1.</p>

<p>PC2: Webservice 8888 (Listen) - Not a problem<br>
PC2: Socket Connect to PC1 port 5555 - Not a problem<br>
PC2: TCP Bridge between the Webservice and the Socket Connect (Problem)  </p>

<p>PC1: TidServer 5555 (Listen) - Not a problem<br>
PC1: TidServer 80 (Listen) - Not a problem<br>
PC1: TCP Bridge between 5555 and 80 (Problem)  </p>

<p>I have come this far:<br>
PC2:<br>
  WSocketLocal Connect local to 8888 (ok)<br>
  WSocketExt Connect external to PC1 port 5555 (ok)  </p>

<pre><code>procedure TWebServForm.WSocketExtDataAvailable(Sender: TObject; ErrCode: Word);
begin
  WSocketLocal.SendStr(WSocketExt.ReceiveStr);
end;

procedure TWebServForm.WSocketLocalDataAvailable(Sender: TObject;
  ErrCode: Word);
begin
  WSocketExt.SendStr(WSocketLocal.ReceiveStr);
end;
</code></pre>

<hr>

<p>PC1:<br>
  IdTCPServer1 listen on 5555 (ok)<br>
  IdTCPServer2 listen on 80 (ok)  </p>

<p>The following two procedures works, So Scenario PC1 is done (working).</p>

<pre><code>procedure TMain.ExtClientDataAvailable(Sender: TObject; Error: Word);
begin
   if Error &lt;&gt; 0 then exit;
   with Sender as TClient do
   begin
      Rcvd := Rcvd + ReceiveStr; 
      if (RemoteSocket.State = wsConnected) and (Rcvd &lt;&gt; '') then
      begin
         WSocketServerLocal.Client[0].SendStr(Rcvd);
         Rcvd := '';
      end;
   end;
end;

procedure TMain.LocalClientDataAvailable(Sender: TObject; Error: Word);
begin
   if Error &lt;&gt; 0 then exit;
   with Sender as TClient do
   begin
      Rcvd := Rcvd + ReceiveStr;
      if (RemoteSocket.State = wsConnected) and (Rcvd &lt;&gt; '') then
      begin
         WSocketServerExt.Client[0].SendStr(Rcvd);
         Rcvd := '';
      end;
   end;
end;
</code></pre>

<p>I want this result:
At PC1: In a webbrowser, <a href="http://127.0.0.1:80" rel="nofollow">http://127.0.0.1:80</a> shows the Webservice of PC2 port 8888</p>

<p>I know there are other and easyier ways to do this, but I have to be exactly as I have described.</p>

<p>How can I make the two "bridges" and what Delphi components should I use ?</p>

<p>Update: I have done the TCP Bridge with two Server Components, now I have to do the same operation with two Connect Components.</p>

<p>Update: I solved it, the two bridges is now working with the written code... But a new problem has appeared... When a webbrowser connects, it can make multiple connections at the same time to a port, my code only supports one connection at a time. I will investigate this.</p>