Autor Beitrag
T0ast3r
Hält's aus hier
Beiträge: 9

Win XP
Delphi 7/8
BeitragVerfasst: Do 05.05.05 15:52 
Hi!

Ist es grundsätzlich möglich, mit Delphi ein Chat Programm zu schreiben?
Mit dem Internet habe ich mich noch nicht so viel auseinandergestzt.
Ich will eben ein Chatt Programm schreiben, und möchte wissen, was ich alles dazu brauch.
Gibt's da eine Komponente?
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Do 05.05.05 16:08 
Sicher ist das mit Delphi möglich.

So ein Chat via TCP/IP ist vor allem ziemlich einfach:

www.delphi-forum.de/...realisieren_120.html
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Do 05.05.05 19:42 
Hi,
ich habe genau zu diesem Link mal ne frage:

Habe mir das gerade mal angeguckt und mal getestet.

Diese beiden:

1 TClientSocket

1 TServerSocket

kann ich aber nicht in der Auswahl finden. Habe Delphi 2005 Architect.
Wo finde ich die beiden Elemente?

_________________
QBasic | Delphi | c++ | PHP | C# .NET | Java
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Do 05.05.05 19:50 
Die gibt es nichtmehr in der Kompoleiste
Deren Unit gibt es glaub ich noch, du kannst sie dann einbetten.
Im DF wird du fündig! :wink:

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Do 05.05.05 20:25 
Sorry, versteh ich nicht.
Alos das es das nicht gibt versteh ich^^ aber wo bekomm ich das her (wenn das geht) und wie binde ich das ein?
der_zaehe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

WinXP SP2
D6 Pers, D2005 Prof, VS2005
BeitragVerfasst: Do 05.05.05 20:39 
du musst das package dclsockets90.bpl manuell nachinstallieren
dann hast du die kompos

_________________
[inspirationslos]
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Do 05.05.05 20:43 
sind die denn normal dabei in nem odner? (Also einfach suchen und dann einbinden?)

Mal ne zusatzfrage: Ist Delphi 5 Delphi 2005?
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 05.05.05 20:47 
Sind die bei D2005 sicher noch dabei?

Sollten Sie es nicht sein, kannst Du das Ganze auch mit den Indys machen, das ist sowieso viel besser, die bieten mehr Möglichkeiten ;-)
Diese findest Du hier: www.indyproject.org/
Dort gibt es auch ein Paket mit Demo-Programmen, da müsste auch ein Chat dabei sein. Einfach die Anleitungen lesen und das Beispiel anschauen, schon bist Du schon Mal schlauer ;-)
der_zaehe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

WinXP SP2
D6 Pers, D2005 Prof, VS2005
BeitragVerfasst: Do 05.05.05 20:50 
ich bin mir ziemlich sicher, das sie noch dabei sind, denn ich habe sie installiert ;) zusätzliches runterladen sollte also nicht nötig sein. gleiches gilt für indy

_________________
[inspirationslos]
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Do 05.05.05 20:51 
OK, danke. Werd mir das mal angucken und sag morgen mal ob das geklappt hat. :D
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 05.05.05 20:53 
user profile iconder_zaehe hat folgendes geschrieben:
ich bin mir ziemlich sicher, das sie noch dabei sind, denn ich habe sie installiert ;) zusätzliches runterladen sollte also nicht nötig sein. gleiches gilt für indy

Yapp, nur findet man dort eben die neueste Version und außerdem sind doch die Demos nicht bei Delphi gleich mit dabei, oder doch?
der_zaehe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

WinXP SP2
D6 Pers, D2005 Prof, VS2005
BeitragVerfasst: Do 05.05.05 20:55 
es gibt tatsächlich im verzeichniss demo nen ordner indy10, jedoch glaub ich jetzt nicht das da so viele beispiele drin sind wie im internet verfügbar sind

_________________
[inspirationslos]
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 05.05.05 21:02 
Nein, da sind nur HTTP-Beispiele dabei, die TCP-Beispiele fehlen.
der_zaehe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 317

WinXP SP2
D6 Pers, D2005 Prof, VS2005
BeitragVerfasst: Do 05.05.05 21:06 
hab ich mir beinahe gedacht :(

_________________
[inspirationslos]
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: Do 05.05.05 21:12 

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Fr 06.05.05 11:26 
Danke für die Hilfe. Habs gefunden und eingefügt *g*.
Nur das läuft nicht so ganz...
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Fr 06.05.05 14:37 
Ich kann bei meinem Server/Client Programm keine Nachrichten verschciken. Auf jeden Fall zeigt er sie nicht bei dem andern an. Die Verbindung steht.

FRAGE: Wie macht man das die Nachricht bei dem anderen "Gesprächspartner" auch in der Memo (oder sonstiges) auftaucht?

_________________
QBasic | Delphi | c++ | PHP | C# .NET | Java
Gosa
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Fr 06.05.05 14:58 
wenn du das mit den indy componenten machst: (ungefähr so)

Server:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TFServer.TCPServerExecute(AThread: TIdPeerThread);
Var Nachricht : String;
    i : integer;
begin
  try
    // Clientnachricht lesen
    Nachricht := AThread.Connection.ReadLn();

    memo1.lines.add(Nachricht);

   except
   End;
end;


Client: (mit einem thread gehts am besten)
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:
type
  TReadThread = class(TThread)
  private
    Nachricht : string;
    procedure EingangVerarbeiten;
  protected
    procedure Execute; override;
  end;

procedure TReadThread.Execute;
begin
  try
    While (not Terminated) and (FClient.TCPClient.Connected) do
    Begin

      Nachricht := FClient.Tcpclient.ReadLn();
      Synchronize(EingangVerarbeiten);

    End;
  except
  end;
end;

procedure TReadThread.EingangVerarbeiten;
Begin
  memo1.lines.add(Nachricht);
End;

procedure TFClient.FormCreate(Sender: TObject);
var i,j : integer;
begin
  Thread := TReadThread.Create(True);
  Thread.FreeOnTerminate := True;
End;


Du musst den thread dann noch irgendwann starten (Thread.resume). Anhalten mach man mit (Thread.suspend).
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Fr 06.05.05 15:00 
habe das aber leider nicht mit Indy gemacht... :-(
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 06.05.05 15:21 
hier mal die erste version von meinem chatprog, ist schon etwas länger her funzt auch nur für 2 personen, danach folgten noch haufenweise versionen, final ist nie ganz fertig geworden aber da funzt alles mit multi chat und teilnehmerliste, aber fürn anfang ist der code zulang (kA wie viele zeilen):
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:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ScktComp, mmsystem, shellapi;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Edit1: TEdit;
    Button1: TButton;
    MainMenu1: TMainMenu;
    Verbindung1: TMenuItem;
    Verbinden1: TMenuItem;
    Unterbrechen1: TMenuItem;
    N1: TMenuItem;
    Beenden1: TMenuItem;
    ClientSocket1: TClientSocket;
    ServerSocket1: TServerSocket;
    ChatLog1: TMenuItem;
    DieseSessionaufzeichnen1: TMenuItem;
    N2: TMenuItem;
    DiesenPCalsServerbenutzen1: TMenuItem;
    Optionen1: TMenuItem;
    Schrift1: TMenuItem;
    FontDialog1: TFontDialog;
    procedure Memo2KeyPress(Sender: TObject; var Key: Char);
    procedure ServerSocket1Accept(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ServerSocket1ClientRead(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocket1Connect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocket1Disconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
    procedure Verbinden1Click(Sender: TObject);
    procedure Beenden1Click(Sender: TObject);
    procedure Memo1KeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Unterbrechen1Click(Sender: TObject);
    procedure DieseSessionaufzeichnen1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure DiesenPCalsServerbenutzen1Click(Sender: TObject);
    procedure ServerSocket1ClientConnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ServerSocket1ClientDisconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure Schrift1Click(Sender: TObject);
    procedure Label2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  protected
  isserver:boolean;
  end;

var
  Form1: TForm1;
  Server, Nick: String;
  recordS: boolean;

  implementation

{$R *.dfm}
{$R sounds.res}

procedure TForm1.Memo2KeyPress(Sender: TObject; var Key: Char);
begin
key:= #0;
end;

procedure TForm1.ServerSocket1Accept(Sender: TObject;
  Socket: TCustomWinSocket);
begin
IsServer := True;
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
memo1.lines.add('');
Memo1.Lines.Add(Socket.ReceiveText);
PlaySound('newmessage',HInstance, snd_ASync or snd_Memory or snd_Resource);
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
ClientSocket1.Socket.SendText(nick + ' ist auf dem Server !');
memo2.text := 'Verbunden mit: ' + Socket.RemoteHost;
end;

procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
memo2.text := 'Verbindung getrennt!';
end;

procedure TForm1.ClientSocket1Error(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
Memo2.text := 'Fehler beim Verbinden mit: ' + Server;
ErrorCode := 0;
end;

procedure TForm1.ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
begin
memo1.lines.add('');
Memo1.Lines.Add(Socket.ReceiveText);
PlaySound('newmessage',HInstance, snd_ASync or snd_Memory or snd_Resource);
end;

procedure TForm1.Verbinden1Click(Sender: TObject);
begin
if ClientSocket1.Active then ClientSocket1.Active := False;
if InputQuery('Verbinden', 'Server-Addresse:', Server) then
if InputQuery('Benutzer', 'Benutzer-Name:', Nick) then
if Length(Server) > 0 then
if length(nick) <= 0 then nick := 'Gast';
with ClientSocket1 do
begin
Host := Server;
Active := True;
end;
end;

procedure TForm1.Beenden1Click(Sender: TObject);
begin
if recordS = true then memo1.lines.SaveToFile('Chat.txt');
ServerSocket1.Close;
ClientSocket1.Close;
Close;
end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
key:= #0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if length(nick) <= 0 then nick := 'Gast';
if edit1.Text <> '' then begin
if IsServer then
ServerSocket1.Socket.Connections[0].SendText(nick + ': ' + edit1.text)
else
ClientSocket1.Socket.SendText(nick + ': ' + edit1.text);
memo1.lines.add('');
memo1.lines.add(nick + ': ' + edit1.Text);
edit1.text:= '';
end;
end;

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if length(nick) <= 0 then nick := 'Gast';
if Key = VK_Return then begin
if edit1.Text <> '' then begin
if IsServer then
ServerSocket1.Socket.Connections[0].SendText(nick + ': ' + edit1.text)
else
ClientSocket1.Socket.SendText(nick + ': ' + edit1.text);
memo1.lines.add('');
memo1.lines.add(nick + ': ' + edit1.Text);
edit1.text:= '';
end;
end;
end;

procedure TForm1.Unterbrechen1Click(Sender: TObject);
begin
ClientSocket1.Active := False;
ServerSocket1.Active := false;
memo2.text := 'Verbindung getrennt!';
end;

procedure TForm1.DieseSessionaufzeichnen1Click(Sender: TObject);
begin
DieseSessionaufzeichnen1.checked:= not DieseSessionaufzeichnen1.checked;
if DieseSessionaufzeichnen1.checked = true then
recordS:= true
else
recordS:= false;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
recordS:= MessageDlg('Möchten Sie die letzte Session speichern?', mtConfirmation, [mbYes,mbNo], 0) = mrYes;
if recordS = true then if recordS = true then memo1.lines.SaveToFile('LastChat.txt');
end;

procedure TForm1.DiesenPCalsServerbenutzen1Click(Sender: TObject);
begin
DiesenPCalsServerbenutzen1.checked:= not DiesenPCalsServerbenutzen1.checked;
if DiesenPCalsServerbenutzen1.checked = true then begin
if length(nick) <= 0 then if InputQuery('Benutzer', 'Benutzer-Name:', Nick) then
if length(nick) <= 0 then nick := 'Gast';
isserver:= true;
serversocket1.active:= true;
memo2.text := 'Server erfolgreich erstellt!';
end else begin
isserver:= false;
serversocket1.active:= false;
memo2.text := 'Server heruntergefahren!';
end;
end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
ServerSocket1.Socket.Connections[0].SendText('Willkommen auf dem Chat42 Server von ' + nick + ' !');
memo2.text := 'Verbunden mit: ' + Socket.RemoteAddress;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
edit1.SetFocus;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
SetBounds((Screen.Width - Width) div 2, (Screen.Height - Height) div 2, Width, Height);
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
memo2.text := 'Verbindung getrennt!';
end;

procedure TForm1.Schrift1Click(Sender: TObject);
begin
if fontdialog1.Execute then memo1.Font:= fontdialog1.Font;
end;

procedure TForm1.Label2Click(Sender: TObject);
begin
{nischt mehr hier}
end;

end.


das ist dann schon sogar etwas mehr als man braucht, wenn du dich ans beipsiel hälst kannst eigentlich net viel falsch machen. :D