菜鸟问题:为何Socket.RemoteHost是空的!(200)

  • 主题发起人 主题发起人 okgprs
  • 开始时间 开始时间
O

okgprs

Unregistered / Unconfirmed
GUEST, unregistred user!
这个程序原先是在UNIX上实现的,UNIX下的shell脚本内容是这样的: telnet 10.36.31.22 9993 > /test/test/aa.txt >> EOF getinfo 1 2 EOF 在form里面定义了四个BitBtn,分别为“连接”,“发送”“断开”“关闭”,一个memo1,一个TClientSocket,一个StatusBarobject:TClientSocketactive:=falseclienttype:=ctNonBlockinghost:=10.36.31.22name:=ClientSocketport:=9993代码uClientMain.pas如下://-------------------------------------------------------------------------------------unit uClientMain;interfaceuses 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);beginBitSend.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);beginStatusBar.Panels[1].Text:='正在连接到服务器... ';showmessage('正在连接到服务器...');end;procedure TForm1.ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);beginMemo1.Lines.Add(ClientSocket.Socket.ReceiveText);end;procedure TForm1.ClientSocketDisconnect(Sender: TObject; Socket: TCustomWinSocket);beginBitSend.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);beginStatusBar.Panels[1].Text:='与服务器端的连接发生错误';ErrorCode:=0;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);beginclose;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);beginClientSocket.Close;end;procedure TForm1.BitCloseClick(Sender: TObject);beginClose; end;end.//-------------------------------------------------------------------------------------问题:1)。打印出来的Socket.RemoteHost是空的,这是为什么? 2). 这个段代码有问题么?哪里需要改进?(本人很少写delphi代码)谢谢!!!!!!!!!
 
[:(]在线等。。。。
 
真的是崩溃。。。。是分数太少,还是问题太简单,大家都不屑回答
 
没有人给点意见么?哎下班前顶一下
 
后退
顶部