Indy SSL到普通套筒泵 [英] Indy SSL to plain socket pump

查看:74
本文介绍了Indy SSL到普通套筒泵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为普通的TCP服务器提供SSL前端,所以我正在制作一个泵"应用程序,该应用程序将提供与外部的SSL连接,而原始服务器可以保持普通状态.

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.

我正在尝试使用Indy组件来满足我的SSL需求,但似乎无法从SSL端口获取任何数据.我将TIdTCPServer.OnExecute分配给以下事件处理程序:

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;

TCP服务器已附加SSL处理程序.我在普通的HTTP服务器上做了同样的事情,并且工作正常,所以我假设我的SSL设置不是问题.

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 =客户端(服务器套接字)和ss =服务器端(我要向其添加SSL的TCP服务器的客户端).

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

现在,我知道它需要清理并且等待1毫秒的等待不是一件好事,但是在我可以解决该问题之前,我想接收一些数据.

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.

我的ReadBytes都没有被调用.当我使用cs.Readable()时,只得到一次true,但仍然无法阅读.

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 make a pump? Why am I not getting data?

推荐答案

尝试直接使用TIdMappedPortTCP组件而不是TIdTCPServer. TIdMappedPortTCP处理在客户端和另一台服务器之间来回传递数据的所有工作.默认情况下,即使到TIdMappedPortTCP的入站连接已加密,也不会加密与第二台服务器的出站连接.

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.

这篇关于Indy SSL到普通套筒泵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆