开发者

Indy SSL to plain socket pump

I have to provide an SSL front for a plain TCP server, so I'm making a "pump" application that will provide an SSL connection to the outside while the original server can stay plain.

I'm trying to use the Indy components to support my SSL needs, but I can't seem to get any data from the SSL port. I assigned the TIdTCPServer.OnExecute to the following event handler:

procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
 c:TIdTCPClient;
 cs,ss:TIdIOHandler;
 b:TBytes;
begin
 c:=TIdTCPClient.Create(Self);
 try
   c.Host:='127.0.0.1';
   c.Port:=60675;
   c.ConnectTimeout:=500;
   c.Connect;
   ss:=c.IOHandler;
   cs:=AContext.Connection.IOHandler;
   while (cs.Connected) and (ss.Connected) do
    begin
     if cs.CheckForDataOnSource(1) then
      begin
       try
        cs.ReadBytes(b,1,False);
       except on e:Exception do
        Memo1.Lines.Add(e.Message); //BAD out of Thread context
       end;
       if Length(b)>0 then
        ss.Write(b);
      end;
     if ss.CheckForDataOnSource(1) then
      begin
       ss.ReadBytes(b,1,False);
       if Length(b)>0 then
        cs.Write(b);
      end;
    end;
 finally
   c.Free;
 end;
end;

The TCP server has an SSL handler attached. I did the same on a plain HTTP server and it worked fine, so I'm assuming my SSL setup is not the issue.

cs=Client Side (the server socket) and ss=Server side (the client for the TCP server I'm trying to add SSL to).

Now, I know it needs cleanup and doing 1ms waits isn't pretty, but before I can attack that issue, I'd like to receive some data.

Neither of my ReadBytes get called. When I used cs.Readable(), I get true just once, but I still couldn't read.

What can I do to m开发者_开发技巧ake a pump? Why am I not getting data?


Try using the TIdMappedPortTCP component instead of TIdTCPServer directly. TIdMappedPortTCP handles all the work of passing data back and forth between a client and another server. By default, the outbound connection to the second server is not encrypted, even if the inbound connection to TIdMappedPortTCP is encrypted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜