用except捕获
try
socket.active = true;
Result := 端口打开 ;
except
Result := 端口没打开;
rasie ;
end
try
socket.active = true;
Result := 端口打开 ;
except
Result := 端口没打开;
rasie ;
end
解决方案 »
- 求助,关于Delphi
- RvDataSetConnection1和RvProject1做随查询结果更新的报表
- {{{{{{{ 请问用什么方法可以这样写入一个文件? }}}}}}}
- 怎样使光标在DBGridEH里垂直移动?
- 想学DELPHI,请各位高手指点明路
- 急急急!!sql高手请进,一个sql语句,就剩30分了,全部送上!!!!急急急急急急!!!!!!!!!!!!!!
- 用dbgrid1的什么方法和属性能在dbgrid1直接添加记录?
- 100分求救,如何把编译好的程序封装进dll文件里面呢?
- 关于如何捕获连接本机的远程IP地址
- 我只有这么多分了,请多多帮忙,有关日期的问题
- 有头文件的文本数据固定格式的读取,头文件和数据文件如下: (我能给出 33 分 多多包涵)
- 想中止WebBrowser控件正在下载的页面,stop()好像不起作用。应该怎么中止下载?
用TClientSocket Connect至此端口,如果Connect成功,则此端口打开。如果产生了 ESocketError exception(Error no:10061), 则此端口未打开。
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
testport: TButton;
procedure testportClick(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.testportClick(Sender: TObject);
begin
with ClientSocket1 do
begin
Close;
Host := 'servername';//servername为要检测的服务器服务器名
Port := 10000;//10000为要检测的服务器端口
Open; end;end;procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
showmessage(format('服务器%s上的端口%d已打开',[ClientSocket1.host,ClientSocket1.port]));
end;procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
showmessage(Format('无法连接服务器%s的端口%d',[ClientSocket1.host,ClientSocket1.port]));
ErrorCode := 0;
end;end.
>> Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
>> var ErrorCode: Integer);
>>begin
>> showmessage(Format('无法连接服务器%s的端口%d',[ClientSocket1.host,ClientSocket1.port]));
>> ErrorCode := 0;
>>end;Connect连接失败的原因有多种,只有当Errcode = 10061 时才能表明服务器端口未打开。