I wish to transfer a small amount of data from one Win32 exe to another Win32 exe. The code I've written uses TTCPServer and TTCPConnect components. It works when compiled using Delphi 7 but fails when compiled using Delphi 2009. In both cases I've run the programs on Windows XP machines.
To demonstrate the problem, I've coded two programs. One called Server and the other called Client.
Here is the code for Client:
This is the code for Server
Each program is started. The Connect button is clicked on the Server application, the Connect button is clicked on the Client application and then the Send button is clicked on the Client application.
When compiled under Delphi 7, the expected text appears in the memo.
When compiled under Delphi 2009, nothing appears in the memo. However, if I click on Connect again in the Client application abcdefghiabcdefghi appears in the memo.
Is anyone aware of problems with the Delphi 2009 TTCPClient and TTCPServer components and if there is a fix?
Andrew
To demonstrate the problem, I've coded two programs. One called Server and the other called Client.
Here is the code for Client:
Code:
unit ClientMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Sockets;
type
TForm1 = class(TForm)
Client: TTcpClient;
btnConnect: TButton;
btnSend: TButton;
edText: TEdit;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure btnSendClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnConnectClick(Sender: TObject);
begin
Client.Disconnect;
Client.RemoteHost := '127.0.0.1';
Client.RemotePort := '2609';
Client.Connect;
if Client.Connected then
Form1.Caption := 'Client Connected';
end;
procedure TForm1.btnSendClick(Sender: TObject);
begin
if Client.Connected then
Client.SendLn( 'abcdefghijklmnop' );
end;
end.
This is the code for Server
Code:
unit ServerMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Sockets;
type
TForm1 = class(TForm)
Server: TTcpServer;
btnConnect: TButton;
log: TMemo;
procedure btnConnectClick(Sender: TObject);
procedure ServerAccept(Sender: TObject; ClientSocket: TCustomIpClient);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnConnectClick(Sender: TObject);
begin
Server.Active := false;
Server.LocalHost := '127.0.0.1';
Server.LocalPort := '2609';
Server.Active := true;
if Server.Active then
Form1.Caption := 'Server Connected';
end;
procedure TForm1.ServerAccept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
s: string;
begin
// log.Lines.Append( ClientSocket.LookupHostName( ClientSocket.RemoteHost ) );
s := ClientSocket.ReceiveLn;
while s <> '' do begin
log.Lines.Append( s );
s := ClientSocket.ReceiveLn;
end;
end;
end.
When compiled under Delphi 7, the expected text appears in the memo.
When compiled under Delphi 2009, nothing appears in the memo. However, if I click on Connect again in the Client application abcdefghiabcdefghi appears in the memo.
Is anyone aware of problems with the Delphi 2009 TTCPClient and TTCPServer components and if there is a fix?
Andrew