简体   繁体   English

TidTCPServer升级问题

[英]TidTCPServer Upgrade Problems

I've recently needed to upgrade an old Delphi 6 project to Delphi 2007. It is a server application using the Indy TidTCPServer component. 我最近需要将旧的Delphi 6项目升级到Delphi2007。这是一个使用Indy TidTCPServer组件的服务器应用程序。 I've followed all the examples I could find on upgrading to Indy 10. 我遵循了所有可以升级到Indy 10的示例。

The application interfaces with an old VB6 application (that we do not have the code for) via TCP/IP. 该应用程序通过TCP / IP与旧的VB6应用程序(我们没有代码)对接。 I'm having a difficult time because the Execute event on the Indy component fires as soon as the VB6 application connects, but it does not write any data. 我很困难,因为只要VB6应用程序连接,Indy组件上的Execute事件就会触发,但是它不会写入任何数据。 This causes the application to hang waiting for the application to send data that never arrives. 这导致应用程序挂起,等待应用程序发送永不到达的数据。

The original code looked like: 原始代码如下所示:


data := AContext.Connection.IOHandler.ReadLn;
if data <> '' then
  begin
    // do some stuff
  end;

I've tried several code examples from the Indy examples, as well as here on StackOverlow. 我已经尝试了Indy示例以及StackOverlow上的几个代码示例。 An example is: 一个例子是:

AContext.Connection.IOHandler.CheckForDataOnSource(10);
if not AContext.Connection.IOHandler.InputBufferIsEmpty then
  begin
    data := AContext.Connection.IOHandler.ReadLn();
    if data <> '' then
      begin
        // do some stuff
      end;
  end;

Strangely enough, the original code works flawlessly when I hit it with a .NET client. 奇怪的是,当我使用.NET客户端访问原始代码时,原始代码可以完美地工作。 This only seems to be a problem coming from the VB6 application. 这似乎只是来自VB6应用程序的问题。

I believe Indy 9 came with Delphi 6 and Indy 10 does come with Delphi 2007 so the problem appears to be the differences between Indy 9 and Indy 10. Unfortunately, Indy 10 was not always backwards compatible. 我相信Indy 9随Delphi 6一起提供,而Indy 10随Delphi 2007一起提供,所以问题似乎出在Indy 9和Indy 10之间。区别是,Indy 10并不总是向后兼容。

Here is a brief overview of some of these changes Object Hierarchy Changes in Indy 10 这是其中一些更改的简要概述Indy 10中的对象层次结构更改

The interesting part is you say the Net client connects fine...assumedly with the unmodified version of your server simply recompiled with Delphi 2007? 有趣的部分是您说Net客户端连接良好……假定与服务器的未修改版本简单地用Delphi 2007重新编译了吗? If so then it sounds like you may have Indy 10 already installed to build your Delphi 6 system... 如果是这样,那么听起来您可能已经安装了Indy 10来构建您的Delphi 6系统...

Sounds like it's time for you to fire up WireShark and see what's actually being sent/received. 听起来好像是时候启动WireShark并查看实际发送/接收的内容。 That might give you the clue that you need. 这可能会为您提供所需的线索。

I had an issue which caused me problems upgrading from Indy 9 to Indy 10 with C++Builder2009. 我遇到了一个问题,这使我无法使用C ++ Builder2009从Indy 9升级到Indy 10。 The TIdTcpClient "Connect" method in Indy 9 has a declaration roughly like this Indy 9中的TIdTcpClient“ Connect”方法具有大致如下的声明

void Connect(int ConnectTimeout);

In Indy10, "ConnectTimeout" is now a property, and the Connect method now has a declaration similar to this: 在Indy10中,“ ConnectTimeout”现在是一个属性,并且Connect方法现在具有类似于以下内容的声明:

void Connect(String HostName);

So my old code with "Connect(5000);" 所以我的旧代码是“ Connect(5000);” compiled fine (because there's an automatic conversion operators from Int to String) was now tried to connect to a host called "5000".... 编译良好(因为从Int到String有自动转换运算符)现在已尝试连接到名为“ 5000”的主机。

Problem solved. 问题解决了。 The following code works... 以下代码有效...


AContext.Connection.IOHandler.CheckForDataOnSource(10);
  if not AContext.Connection.IOHandler.InputBufferIsEmpty then
    begin
      data := AContext.Connection.IOHandler.InputBuffer.Extract;

After closely inspecting the stream (as suggested by @Roddy), I was able to determine that the VB6 application was not sending a CRLF on the connections, which was causing the AContext.Connection.IOHandler.ReadLn; 经过仔细检查流(如@Roddy所建议),我能够确定VB6应用程序未在连接上发送CRLF,这导致了AContext.Connection.IOHandler.ReadLn; to block waiting for a CRLF that never came. 阻止等待从未出现的CRLF。

Thank you @Darian and @Roddy for helping me find the answer. 谢谢@Darian和@Roddy帮助我找到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM