这个程序原先是在UNIX上实现的,UNIX下的shell脚本内容是这样的: 
telnet  10.36.31.22 9993 >  /test/test/aa.txt >> EOF 
getinfo 1  2 
EOF 

在form里面定义了四个BitBtn,分别为“连接”,“发送”“断开”“关闭”,一个memo1,一个TClientSocket,一个StatusBar
object:TClientSocket
active:=false
clienttype:=ctNonBlocking
host:=10.36.31.22
name:=ClientSocket
port:=9993


代码uClientMain.pas如下:
//-------------------------------------------------------------------------------------
unit uClientMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, ScktComp, StdCtrls, Buttons;
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Memo1: TMemo;
    ClientSocket: TClientSocket;
    StatusBar: TStatusBar;
    BitConnect: TBitBtn;
    BitSend: TBitBtn;
    BitDisconnect: TBitBtn;
    BitClose: TBitBtn;
    procedure FormShow(Sender: TObject);
    procedure ClientSocketConnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocketConnecting(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure ClientSocketDisconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BitConnectClick(Sender: TObject);
    procedure BitSendClick(Sender: TObject);
    procedure BitDisconnectClick(Sender: TObject);
    procedure BitCloseClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.FormShow(Sender: TObject);
begin
//ClientSocket.Host:=SocketHost;

end;

procedure TForm1.ClientSocketConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
BitSend.Enabled:=True;
BitDisconnect.Enabled:=True;
BitClose.Enabled:=True;
StatusBar.Panels[1].Text:= '已经连接到'+Socket.RemoteHost;
showmessage('已经连接到'+Socket.RemoteHost);
end;

procedure TForm1.ClientSocketConnecting(Sender: TObject;
  Socket: TCustomWinSocket);
begin
StatusBar.Panels[1].Text:='正在连接到服务器... ';
showmessage('正在连接到服务器...');
end;

procedure TForm1.ClientSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
Memo1.Lines.Add(ClientSocket.Socket.ReceiveText);
end;

procedure TForm1.ClientSocketDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
BitSend.Enabled:=False;
BitDisconnect.Enabled:=False;
StatusBar.Panels[1].Text:='已经断开与'+Socket.RemoteHost+'的连接';
//StatusBar.Panels[1].Text:='已经断开与'+ClientSocket.Socket.RemoteHost;+'的连接';
Memo1.Lines.Add('已经断开与'+Socket.RemoteHost+'的连接');
end;

procedure TForm1.ClientSocketError(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
StatusBar.Panels[1].Text:='与服务器端的连接发生错误';
ErrorCode:=0;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
close;
end;

procedure TForm1.BitConnectClick(Sender: TObject);
begin
 ClientSocket.Open;
end;

procedure TForm1.BitSendClick(Sender: TObject);
begin
//ClientSocket.Socket.SendText(Edit1.Text);
ClientSocket.Socket.SendText('getinfo 1  2');
end;

procedure TForm1.BitDisconnectClick(Sender: TObject);
begin
ClientSocket.Close;
end;

procedure TForm1.BitCloseClick(Sender: TObject);
begin
Close; 
end;

end.

//-------------------------------------------------------------------------------------

问题:1)。打印出来的Socket.RemoteHost是空的,这是为什么?
      2). 这个段代码有问题么?哪里需要改进?(本人很少写delphi代码)

谢谢!!!!!!!!!