请问如何监视本机内某一个端口是否开启(Port as 80 ..) 可以用TServiceSocket,然后把Port设为80没有经过考证,使用后果自负:) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 至于知道端口是否打开,可以写汇编程序,测试8250的数据发送寄存器。这是一个串口的监听的例子,看看有没有用:unit frmComm; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,GeoUtils,GeoGPS; const MAXBLOCK = 160; type TComm = record idComDev : THandle; fConnected : Boolean; end; TCommForm = class(TForm) ComboBox1: TComboBox; Button1: TButton; StatusBar1: TStatusBar; Button2: TButton; ComboBox2: TComboBox; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; TCommThread = Class(TThread) protected procedure Execute;override; public constructor Create; end; var CommForm: TCommForm; CommHandle : THandle; Connected : Boolean; CommThread : TCommThread; implementation {$R *.DFM} uses frmMain,frmMdiMapView; procedure TCommThread.Execute; var dwErrorFlags,dwLength : DWORD; ComStat : PComStat; fReadStat : Boolean; InChar : Char; AbIn : String; XX,YY : double; file://经度、纬度 VID : string; file://车号 begin while Connected do begin GetMem(ComStat,SizeOf(TComStat)); ClearCommError(CommHandle, dwErrorFlags, ComStat); if (dwErrorFlags > 0) then begin PurgeComm(CommHandle,(PURGE_RXABORT and PURGE_RXCLEAR)); // return 0; end; dwLength := ComStat.cbInQue; if (dwLength>0) then begin fReadStat := ReadFile(CommHandle, InChar, 1,dwLength, nil); if (fReadStat) then begin if (InChar <> Chr(13)) and (Length(abIn) < MAXBLOCK+5 ) then AbIn := AbIn + InChar else begin ... {接收完毕,} end;//if (fReadStat>0){ end; file://if (dwLength>0){ FreeMem(ComStat); end;{while} end; constructor TCommThread.Create; begin FreeOnTerminate := TRUE; inherited Create(FALSE); file://Createsuspended = false end; // procedure TCommForm.Button1Click(Sender: TObject); var CommTimeOut : TCOMMTIMEOUTS; DCB : TDCB; fRetVal : Boolean; begin StatusBar1.SimpleText := '连接中...'; CommHandle := CreateFile(PChar(ComboBox1.Text),GENERIC_READ,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL , 0); if CommHandle = INVALID_HANDLE_VALUE then begin StatusBar1.SimpleText := '连接失败'; Exit; end; StatusBar1.SimpleText := '已同端口 '+ ComboBox1.Text + ' 连接!'; CommTimeOut.ReadIntervalTimeout := MAXDWORD; CommTimeOut.ReadTotalTimeoutMultiplier := 0; CommTimeOut.ReadTotalTimeoutConstant := 0; SetCommTimeouts(CommHandle, CommTimeOut); GetCommState(CommHandle,DCB); DCB.BaudRate := 9600; DCB.ByteSize := 8; DCB.Parity := NOPARITY; DCB.StopBits := ONESTOPBIT; fRetVal := SetCommState(CommHandle, DCB); if (fRetVal) then begin Connected := TRUE; try CommThread := TCommThread.Create; except Connected := FALSE; CloseHandle(CommHandle); fRetVal := FALSE; StatusBar1.SimpleText := '线程建立失败'; Exit; end; end else begin Connected := FALSE; CloseHandle(CommHandle); end; end; procedure TCommForm.Button2Click(Sender: TObject); begin Connected := FALSE; CloseHandle(CommHandle); {终止线程} CommThread.Terminate; StatusBar1.SimpleText := '关闭端口'+ComboBox1.Text; end; procedure TCommForm.FormClose(Sender: TObject; var Action: TCloseAction); begin Connected := FALSE; CloseHandle(CommHandle); StatusBar1.SimpleText := '关闭端口'+ComboBox1.Text; end; end. 问一条SQL语句,和DBGRID显示问题 关于AdoStoredProc控件传入参数的问题:传给变量的字段长度有没有限制啊!!,盼高手 用流来处理图象插入数据库遇到可凝的问题!! Sql语句创建表得问题! 關于 windows.pas 多元一次方程组的解法(算法)??? 请问各位大虾这DELPHI6企业版哪里有的下载????????????????????????? 关于数据库中记录的时间与系统时间的比较 一个delphi下的报表控件,请大家测试,多多提出改进意见,谢谢. 程序调用的问题 100分求解midas多层系统数据连接问题!!!急,高手请进!!! 怎样使用文件型数据库?
这是一个串口的监听的例子,看看有没有用:
unit frmComm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls,GeoUtils,GeoGPS;
const MAXBLOCK = 160;
type
TComm = record
idComDev : THandle;
fConnected : Boolean;
end;
TCommForm = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
StatusBar1: TStatusBar;
Button2: TButton;
ComboBox2: TComboBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
TCommThread = Class(TThread)
protected
procedure Execute;override;
public
constructor Create;
end;
var
CommForm: TCommForm;
CommHandle : THandle;
Connected : Boolean;
CommThread : TCommThread;
implementation
{$R *.DFM}
uses
frmMain,frmMdiMapView;
procedure TCommThread.Execute;
var
dwErrorFlags,dwLength : DWORD;
ComStat : PComStat;
fReadStat : Boolean;
InChar : Char;
AbIn : String;
XX,YY : double; file://经度、纬度
VID : string; file://车号
begin
while Connected do begin
GetMem(ComStat,SizeOf(TComStat));
ClearCommError(CommHandle, dwErrorFlags, ComStat);
if (dwErrorFlags > 0) then begin
PurgeComm(CommHandle,(PURGE_RXABORT and PURGE_RXCLEAR));
// return 0;
end;
dwLength := ComStat.cbInQue;
if (dwLength>0) then begin
fReadStat := ReadFile(CommHandle, InChar, 1,dwLength, nil);
if (fReadStat) then begin
if (InChar <> Chr(13)) and (Length(abIn) < MAXBLOCK+5 ) then AbIn := AbIn + InChar
else begin
...
{接收完毕,}
end;//if (fReadStat>0){
end; file://if (dwLength>0){
FreeMem(ComStat);
end;{while}
end;
constructor TCommThread.Create;
begin
FreeOnTerminate := TRUE;
inherited Create(FALSE); file://Createsuspended = false
end;
//
procedure TCommForm.Button1Click(Sender: TObject);
var
CommTimeOut : TCOMMTIMEOUTS;
DCB : TDCB;
fRetVal : Boolean;
begin
StatusBar1.SimpleText := '连接中...';
CommHandle := CreateFile(PChar(ComboBox1.Text),GENERIC_READ,0,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL
, 0);
if CommHandle = INVALID_HANDLE_VALUE then begin
StatusBar1.SimpleText := '连接失败';
Exit;
end;
StatusBar1.SimpleText := '已同端口 '+ ComboBox1.Text + ' 连接!';
CommTimeOut.ReadIntervalTimeout := MAXDWORD;
CommTimeOut.ReadTotalTimeoutMultiplier := 0;
CommTimeOut.ReadTotalTimeoutConstant := 0;
SetCommTimeouts(CommHandle, CommTimeOut);
GetCommState(CommHandle,DCB);
DCB.BaudRate := 9600;
DCB.ByteSize := 8;
DCB.Parity := NOPARITY;
DCB.StopBits := ONESTOPBIT;
fRetVal := SetCommState(CommHandle, DCB);
if (fRetVal) then begin
Connected := TRUE;
try
CommThread := TCommThread.Create;
except
Connected := FALSE;
CloseHandle(CommHandle);
fRetVal := FALSE;
StatusBar1.SimpleText := '线程建立失败';
Exit;
end;
end
else begin
Connected := FALSE;
CloseHandle(CommHandle);
end;
end;
procedure TCommForm.Button2Click(Sender: TObject);
begin
Connected := FALSE;
CloseHandle(CommHandle);
{终止线程}
CommThread.Terminate;
StatusBar1.SimpleText := '关闭端口'+ComboBox1.Text;
end;
procedure TCommForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Connected := FALSE;
CloseHandle(CommHandle);
StatusBar1.SimpleText := '关闭端口'+ComboBox1.Text;
end;
end.