|
ActiveDelphi .: O site do programador Delphi! :.
|
Exibir mensagem anterior :: Exibir próxima mensagem |
Autor |
Mensagem |
cgm2k7 Novato
Registrado: Quinta-Feira, 13 de Setembro de 2007 Mensagens: 46
|
Enviada: Sáb Set 19, 2015 7:39 am Assunto: portaTCP |
|
|
ola pessoal estou aqui mais uma vez precisando de ajuda:
no meu aplicativo preciso saber se uma de determinada porta TCP
esta aberta(3724),
Achei vários a maiorias deu certo, mas o quer não deu certo
para minha aplicação é que quando a porta esta fechada
o form trava por alguns segundo só não trava quando a porta esta aberta, veja abaixo ums de vários códigos q achei na net...
Código: |
procedure TForm2.TestarPorta(host: string; port: integer);
begin
TcpClient1.RemoteHost := host;
TcpClient1.RemotePort := IntToStr(port);
if TcpClient1.Connect then
ShowMessage(IntToStr(port))
else
ShowMessage('não');
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
TestarPorta(Edit1.Text, StrToInt(Edit2.Text));
end;
|
|
|
Voltar ao Topo |
|
|
cgm2k7 Novato
Registrado: Quinta-Feira, 13 de Setembro de 2007 Mensagens: 46
|
Enviada: Seg Set 21, 2015 6:30 pm Assunto: |
|
|
help-me |
|
Voltar ao Topo |
|
|
DonOctavioDelFlores Colaborador
Registrado: Quarta-Feira, 12 de Setembro de 2007 Mensagens: 2630 Localização: Pra lá de Bagda
|
Enviada: Qua Set 23, 2015 1:36 am Assunto: |
|
|
Se voce não quer que fique travando use uma thread.
Mas de qualquer forma se o software precisa acessar a porta a e porta esta indisponivel tem que esperar o timeout.
Uma solução seria configurar o timeout para ser bem curto, assim não tem que ficar esperando. Deve ter config para ele no indy. _________________ “The problem with the world is that everyone is a few drinks behind.” Humphrey Bogart |
|
Voltar ao Topo |
|
|
cgm2k7 Novato
Registrado: Quinta-Feira, 13 de Setembro de 2007 Mensagens: 46
|
Enviada: Qua Set 23, 2015 10:25 am Assunto: |
|
|
DonOctavioDelFlores escreveu: | Se voce não quer que fique travando use uma thread.
Mas de qualquer forma se o software precisa acessar a porta a e porta esta indisponivel tem que esperar o timeout.
Uma solução seria configurar o timeout para ser bem curto, assim não tem que ficar esperando. Deve ter config para ele no indy. |
sou novato em delphi
tem algum exemplo ae deste "thread"
rsrsr |
|
Voltar ao Topo |
|
|
cgm2k7 Novato
Registrado: Quinta-Feira, 13 de Setembro de 2007 Mensagens: 46
|
Enviada: Sex Set 25, 2015 1:43 pm Assunto: Imgem no listbox in porta-TCP |
|
|
vlw "DonOctavioDelFlores" pesquisei sobre 'uThreads' e consegui achar uma
agora minha duvida é o segui-te:
tenho um listbox onde ele pega de de um arquivo INI: as malformações::
arquivo INI
Código: | [wow-brasil]
realmlist=realm.wow-brasil.com
[Eternalwow]
realmlist=logon.eternal-wow.com
[NoOnline]
realmlist=noip
[MeuIp]
realmlist=localhost |
já consegui um pouco do que eu queria que é quando clica no item do listbox a uThreads verificar se uma determinada por esta aberta se
estiver aberta uma imagem da cor verde fica visível se estiver fechada
a imagem fica vermelha,
o que eu quer agora é que em cada item do listbox apareça se ele esta online ou ofline com uma imagem tipo verde para online vermelha para ofline.
Já achei alguns code para coloca imagem em um listbox mas nenhum deu certo como eu quero . Vejo o fonte abaixo coloquei para download também:
http://www.mediafire.com/download/rld8gll4581z4p5/Realm_List2015.rar
fonte
Código: | unit RealmListModificador;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Buttons, Vcl.StdCtrls, IniFiles,
acPNG;
type
TRealmForm1 = class(TForm)
Image1: TImage;
SpeedButton1: TSpeedButton;
Lista_ListBox1: TListBox;
Label1: TLabel;
Sp_add: TSpeedButton;
Sp_del: TSpeedButton;
Sp_Edi: TSpeedButton;
SpeedButton2: TSpeedButton;
GroupBox1: TGroupBox;
Panel1: TPanel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Image_OfLine: TImage;
Image_Online: TImage;
Label6_Status: TLabel;
Label6_CheckStatus: TLabel;
Label_invisivel: TLabel;
Timer1cicero: TTimer;
SpeedButton3: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SpeedButton1Click(Sender: TObject);
procedure Sp_addClick(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure Lista_ListBox1Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
TReadINIFile:TiniFile;
procedure TimeProcedure;
procedure LerE_GravaArqINI;
procedure status_do_SERVER(Sender: TObject);
{ Public declarations }
end;
var
RealmForm1: TRealmForm1;
implementation
uses Form_Adicionar, uThreads;
{$R *.dfm}
//-----------------------------------------------------\
procedure TRealmForm1.LerE_GravaArqINI;
var FileINIs : String; //\RealmListModificador.ini
begin
FileINIs:='RealmListModificador.ini';
If not FileExists(ExtractFilePath(Application.ExeName)+FileINIs) then begin
ShowMessage('Arquivo de Configuração '+FileINIs+' Não exite ou está conrrompido!')
end else
TReadINIFile:= TIniFile.Create(ExtractFilePath(Application.ExeName)+FileINIs);
end; //TReadINIFile.Free;
//-----------------------------------------------------\
procedure TRealmForm1.status_do_SERVER(Sender: TObject);
var K, porta: integer;
ip: string;
begin
porta:= (3724);
for K:= 0 to Lista_ListBox1.Items.Count -1 do begin
if Lista_ListBox1.Selected[K] then begin
LerE_GravaArqINI;
ip:= TReadINIFile.ReadString(Lista_ListBox1.Items[K], 'realmlist','');
begin
TPortScanner.Create(ip,IntToStr(porta),Label_invisivel);
Lista_ListBox1.Repaint;
TReadINIFile.Free;
if Label_invisivel.Caption = IntToStr(porta) then
Label6_CheckStatus.Caption := 'Online'
else
Label6_CheckStatus.Caption:= 'Ofline';
if Label_invisivel.Caption = IntToStr(porta) then begin
Image_Online.Visible:= true ;
Image_OfLine.Visible:= false;
Label6_CheckStatus.Font.Color:= clGreen;
end;
if not (Label_invisivel.Caption = IntToStr(porta)) then begin
Image_Online.Visible:= false;
Image_OfLine.Visible:= true;
Label6_CheckStatus.Font.Color:= clGray;
end;
Label_invisivel.Caption:= '';
end;
break;
end;
end;
end;
procedure TRealmForm1.TimeProcedure;
begin
Timer1cicero.Enabled := TRUE;
Timer1cicero.Interval := 1000;
Timer1cicero.Ontimer := status_do_SERVER;
end;
procedure TRealmForm1.Lista_ListBox1Click(Sender: TObject);
var
k: integer;
begin
for k:= 0 to Lista_ListBox1.Count -1 do
if (Lista_ListBox1.Selected[k] = true) then begin
LerE_GravaArqINI; // Abrir arquivo .INI
Label4.Caption:= TReadINIFile.ReadString(Lista_ListBox1.Items.Strings[Lista_ListBox1.ItemIndex],'realmlist','') ;
Label5.Caption:= TReadINIFile.ReadString('Config','LocalWow','');
//sMemo1.Lines.Add(TReadINIFile.ReadString(Lista_ListBox1.Items.Strings[Lista_ListBox1.ItemIndex], 'realmlist', ''));
//sMemo1.Lines.Add('');
//sMemo1.Lines.Add(TReadINIFile.ReadString('Config', 'LocalWow', ''));
//RealmForm1.sEdit1.Text:= (TReadINIFile.ReadString(Lista_ListBox1.Items.Strings[Lista_ListBox1.ItemIndex], 'WowLocal', ''));
break;
TReadINIFile.Free; // Frechar arquivo .INI
end;
TimeProcedure;
end;
procedure TRealmForm1.FormCreate(Sender: TObject);
begin
if not FileExists(ExtractFilePath(Application.ExeName)+'RealmListModificador.ini') then begin
TReadINIFile:= TIniFile.Create(ExtractFilePath(Application.ExeName)+ '\RealmListModificador.ini');
TReadINIFile.WriteString('Config', 'LocalWow', 'wow.exe');
TReadINIFile.WriteString('Config', 'DATA', DateToStr(now));
TReadINIFile.Free;
end;
SpeedButton2.Click;
end;
procedure TRealmForm1.FormShow(Sender: TObject);
var
i : integer;
begin
LerE_GravaArqINI;
TReadINIFile.ReadSections(Lista_ListBox1.Items);
begin
for i:=0 to Lista_ListBox1.Items.Count -1 do begin
if (Lista_ListBox1.Items.Strings[i]) = 'Config' then begin
Lista_ListBox1.Items.Delete(i);
break;
begin
TReadINIFile.Free;
end;
end;
end;
end;
end;
procedure TRealmForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
SC_DRAGMOVE = $F012;
begin
if Button = mbLeft then
begin
ReleaseCapture;
Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
end;
end;
procedure TRealmForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
SC_DRAGMOVE = $F012;
begin
if Button = mbLeft then
begin
ReleaseCapture;
Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
end;
end;
procedure TRealmForm1.SpeedButton1Click(Sender: TObject);
begin
RealmForm1.Close;
Application.Terminate;
end;
procedure TRealmForm1.SpeedButton2Click(Sender: TObject);
const
RollUpHt = 369;
DropDownHt = 428;
begin
with TControl(Sender).Parent do
if (Height < RollUpHt + 5) then
begin
while Height <DropDownHt> RollUpHt do begin
Height := Height - 6;
//Refresh; Sleep(01);
end;
end;
procedure TRealmForm1.SpeedButton3Click(Sender: TObject);
begin
status_do_SERVER(Sender);
end;
procedure TRealmForm1.Sp_addClick(Sender: TObject);
begin
Add_Form2.ShowModal;
end;
end. |
se alguém poder me ajuda agradeço |
|
Voltar ao Topo |
|
|
claudio.ferreira Profissional
Registrado: Quarta-Feira, 18 de Setembro de 2013 Mensagens: 667
|
|
Voltar ao Topo |
|
|
|
|
Enviar Mensagens Novas: Proibido. Responder Tópicos Proibido Editar Mensagens: Proibido. Excluir Mensagens: Proibido. Votar em Enquetes: Proibido.
|
|