Autor Beitrag
FrEaKY
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 235


D7
BeitragVerfasst: Do 12.08.04 13:07 
moin ich wollt ma mit indy ein chat proggn aber es funzt überhauptnix... ich wollts so machen der server startet, der client meldet sich an und schickt den nick namen und ip dem server rüber (?) weil ich net weiß wie es sonst geht.
hier is der code ... server:
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:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent, IdTCPServer,Winsock;

type
  TForm1 = class(TForm)
    Bevel1: TBevel;
    Label1: TLabel;
    Edit1: TEdit;
    Bevel2: TBevel;
    Label2: TLabel;
    ListBox1: TListBox;
    Label3: TLabel;
    StaticText1: TStaticText;
    CheckBox1: TCheckBox;
    Bevel3: TBevel;
    Memo1: TMemo;
    Edit2: TEdit;
    Button1: TButton;
    Bevel4: TBevel;
    Label4: TLabel;
    ListBox2: TListBox;
    Button2: TButton;
    Label5: TLabel;
    Edit3: TEdit;
    Server1: TIdTCPServer;
    Bevel5: TBevel;
    Label6: TLabel;
    Label7: TLabel;
    Edit4: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Edit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button1Click(Sender: TObject);
    procedure Server1Exception(AThread: TIdPeerThread;
      AException: Exception);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1; PCname,ip,oldnick,newnick:string;

implementation

{$R *.dfm}

FUNCTION GetIpAddressByName(const AComputerName: STRING): STRING;
VAR
  TMPResult: STRING;
  WSA: TWSAData;
  H: PHostEnt;
  P: PChar;
BEGIN
  IF WSAStartUp($101, WSA) = 0 THEN
    BEGIN
      GetMem(P,255 + 1);
      StrPCopy(P, AComputerName);
      H:=GetHostByName(P);
      FreeMem(P);
      IF H <> NIL THEN
        BEGIN
          P:=inet_ntoa(PInAddr(H^.h_addr_list^)^);
          TMPResult:=StrPas(P)
        END;
      WSACleanUp;
      IF TMPResult <> '' THEN
        Result:=TMPResult
      ELSE
          Result:= '0';
    END;
END;


function GetComputerName: String;
var
  Buffer: Array[0..MAX_COMPUTERNAME_LENGTH+1] of Char;
  Size: DWORD;
begin
  size:=1024;
  Windows.GetComputerName(Buffer, Size);
  Result:=StrPas(Buffer);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  listbox1.ItemIndex := 0;
  pcname := getcomputername;
  ip := getipaddressbyname(pcname);
  sleep(10);
  statictext1.Caption := ip;
  oldnick := edit4.Text;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  server1.active := checkbox1.Checked;
  if checkbox1.Checked then
    begin
      button1.Enabled := true;
      button2.Enabled := true;
      if server1.Active = true then
        begin
         listbox1.Items.Add('*** server activated ***');
         listbox1.ItemIndex := listbox1.ItemIndex +1;
        end;
    end else
    begin
      button1.Enabled := false;
      button2.Enabled := false;
      listbox1.Items.Add('*** server stopped ***');
      listbox1.ItemIndex := listbox1.ItemIndex +1;
    end;
end;

procedure TForm1.Edit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if key = vk_return then
    button1.Click;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    if not (edit2.text<>'' )then exit;
    beep();
    memo1.Lines.add(oldnick+' ['+timetostr(now)+']: '+edit2.Text);
    sleep(10);
    edit2.Clear;
end;

procedure TForm1.Server1Exception(AThread: TIdPeerThread;
  AException: Exception);
begin
 server1.Active := false;
 memo1.Lines.add('INDY CHAT has noticed a problem');
end;

end.
client:
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:
105:
106:
107:
108:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Bevel1: TBevel;
    Label1: TLabel;
    Edit1: TEdit;
    Bevel2: TBevel;
    Label2: TLabel;
    ListBox1: TListBox;
    Label3: TLabel;
    CheckBox1: TCheckBox;
    Bevel3: TBevel;
    Memo1: TMemo;
    Edit2: TEdit;
    Button1: TButton;
    Bevel5: TBevel;
    Label6: TLabel;
    Label7: TLabel;
    Edit4: TEdit;
    client1: TIdTCPClient;
    Edit3: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Edit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1; PCname,oldnick,newnick:string;

implementation

{$R *.dfm}



function GetComputerName: String;
var
  Buffer: Array[0..MAX_COMPUTERNAME_LENGTH+1] of Char;
  Size: DWORD;
begin
  size:=1024;
  Windows.GetComputerName(Buffer, Size);
  Result:=StrPas(Buffer);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  edit4.Text:=getcomputername;
  listbox1.ItemIndex := 0;
  pcname := getcomputername;
  sleep(10);
  oldnick := edit4.Text;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if checkbox1.Checked then
    begin
      client1.Host := edit3.Text;
      client1.Port := strtoint(edit1.Text);
      client1.Connect;
      button1.Enabled := true;
      if client1.Connected = true then
        begin
         listbox1.Items.Add('*** you have been connected to server ***');
         listbox1.ItemIndex := listbox1.ItemIndex +1;
        end;
    end else
    begin
      button1.Enabled := false;
      listbox1.Items.Add('*** disconnected ***');
      listbox1.ItemIndex := listbox1.ItemIndex +1;
    end;
end;

procedure TForm1.Edit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if key = vk_return then
    button1.Click;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
    if not (edit2.text<>'' )then exit;
    beep();
    memo1.Lines.add(oldnick+' ['+timetostr(now)+']: '+edit2.Text);
    sleep(10);
    edit2.Clear;
end;


end.
danke schonmal für hilfe :D
inselberg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458



BeitragVerfasst: Do 12.08.04 13:31 
afaik hat indy doch demos ... einfach abschreibe n;)

_________________
hans bist du das ?
FrEaKY Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 235


D7
BeitragVerfasst: Do 12.08.04 14:46 
hab ich schon aber es geht ja trotzdem net.
blumengiesser
Hält's aus hier
Beiträge: 1

XP
Delphi
BeitragVerfasst: Do 12.08.04 16:24 
hi,

also ich bin auch nen bissle der delphi / indy neuling und muß sagen so wirklich gut dokumentiert sind die ganzen indy sachen nicht grad. hat einer mal nen chat oder udp client/server oder ähnliches was auch funzt, das bricht bei mir immer ab weil der compiler TIdBytes nicht findet. wäre schön, wenn ich da antwort drauf erhalten würde...

gruß
tino
doubleq
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Fr 13.08.04 17:45 
Suche die Unit, in der TIdBytes deklariert sind und füge sie manuell in die uses-Klausel ein, wenn sie da noch nicht steht. Dann sollte es funktionieren.

Wirklich gut dokumentiert ist INDY wirklich nicht, aber mit den Demos kommt man da schon hin, wenn man sich ein bißchen Zeit nimmt...

Gruß DoubleQ