Autor Beitrag
jfheins
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: Do 10.06.04 21:33 
ich möchte gerne den clienten und den server in einem programm unterbringen, das ganze soll ein programm werden, mit dem man dateien im netzwerk veschicken kann.
je nach bedarf muss es also client oder server sein ...
ich bin übrigens recht neu in delphi, also bitte kein fachchinesisch :wink:
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Do 10.06.04 22:13 
Erstens: Willkommen im Forum.

Also wenn Du neu in Delphi bist, wuerde ich Dir raten, nich gleich mit der Tuer ins Haus oder mit dem Client in den Server zu stuerzen (is spaet, ich weiss). Ich empfehle UDP-Broadcasting, also ne Message ins Netz broadcasten (ohne direkten Empfaenger schicken). Is nur dumm, dass so ziemlich jeder Rechner im Netz das abfangen kann.

Ich wuerde mir folgende Struktur ausdenken:


    Liste mit den ClientIPs und Join-Zeitpunkt auf jedem Client
    Zu jedem Client in dieser Liste werden die Nachrichten geschickt.
    Faellt ein Client aus (der, der Server war), wird automatisch der naechste Client in der Liste zum Server und da die anderen Clients auch die Liste haben, wissen sie, wo sie hinconnecten muessen.


Was besseres faellt mir zu diesem Zeitpunkt nicht ein.

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
jfheins Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: Sa 12.06.04 15:00 
Titel: Fehler im Code ?
Ich habe folgenden Quelltext entwickelt, jedoch hat er früher gefunzt, und jetzt nicht mehr, woan liegt das ??? (Funktionierte ohne Write und ReadLn)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdThreadMgr, IdThreadMgrDefault, IdTCPServer, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, StdCtrls;

type
  TForm1 = class(TForm)
    IdTCPClient1: TIdTCPClient;
    IdTCPServer1: TIdTCPServer;
    IdThreadMgrDefault1: TIdThreadMgrDefault;
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure IdTCPServer1Execute(AThread: TIdPeerThread);
    procedure Edit1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  mess1, mess2: string;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
IdTCPServer1.Active := TRUE;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPServer1.Active := FALSE;


if (Edit1.Text <> 'Bitte IP eingeben') then
begin
if (Edit1.Text <> '') then
begin
IdTCPClient1.Host := Edit1.Text;
IdTCPClient1.Port := 2222;
IdTCPClient1.Connect;

IdTCPClient1.Write('Hallo');
mess2 := IdTCPClient1.ReadLn();
showmessage (mess2);

IdTCPClient1.Disconnect;
end;
end;

IdTCPServer1.Active := TRUE;
end;

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
mess1 := AThread.Connection.ReadLn();
showmessage (mess1);
AThread.Connection.Write('Hallo vom Server');
end;

procedure TForm1.Edit1Click(Sender: TObject);
begin
Edit1.Text := '';
end;

end.

Moderiert von user profile iconPeter Lustig: Code- durch Delphi-Tags ersetzt.
jfheins Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: Sa 12.06.04 21:51 
Titel: Hat sich geklärt
Hat sich geklärt, anbei der sourcecode für ein simplen chat
(ein prog, das zum senden kurz zum client wird)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdThreadMgr, IdThreadMgrDefault, IdTCPServer, IdBaseComponent, ComCtrls,
  IdComponent, IdSocketHandle, IdTCPConnection, IdTCPClient, StdCtrls, WinSock,
  IdAntiFreezeBase, IdAntiFreeze;

type
  TForm1 = class(TForm)
    IdTCPClient1: TIdTCPClient;
    IdTCPServer1: TIdTCPServer;
    IdThreadMgrDefault1: TIdThreadMgrDefault;
    Button1: TButton;
    ComboBox1: TComboBox;
    IdAntiFreeze1: TIdAntiFreeze;
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure IdTCPClient1Connected(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure IdTCPServer1Execute(AThread: TIdPeerThread);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  mess1, mess2: string;
  Binding : TIdSocketHandle;
 // CommBlock, NewCommBlock: TCommBlock;

implementation

{$R *.dfm}

function GetIp: string;
var phoste: PHostEnt;
  Buffer: array [0..100] of char;
  WSAData: TWSADATA;
begin
  result:='';
  if WSAStartup($0101, WSAData) <> 0 then exit;
  GetHostName(Buffer,Sizeof(Buffer));
  phoste:=GetHostByName(buffer);
  if phoste = nil then result:='127.0.0.1'
  else result:=StrPas(inet_ntoa(PInAddr(phoste^.h_addr_list^)^));
  WSACleanup;
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
IdTCPServer1.Active := FALSE;

IdTCPServer1.Bindings.Clear;
Binding := IdTCPServer1.Bindings.Add;
Binding.IP := GetIP;
Binding.Port := 2222;

IdTCPServer1.Active := TRUE;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPServer1.Active := FALSE;

if (Combobox1.Text <> 'Bitte IP eingeben') then
begin
if (Combobox1.Text <> '') then
begin
IdTCPClient1.Host := Combobox1.Text;
IdTCPClient1.Port := 2222;
IdTCPClient1.Connect;
end;
end;

IdTCPServer1.Active := TRUE;
end;

procedure TForm1.IdTCPClient1Connected(Sender: TObject);
begin
IdTCPClient1.WriteLn(Edit1.Text);
IdTCPClient1.Disconnect;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IdTCPServer1.Active := FALSE;
IdTCPServer1.Destroy;
IdTCPClient1.Destroy;
end;

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
showmessage (AThread.Connection.ReadLn());
end;

end.