Registriert seit: 10. Aug 2006
129 Beiträge
|
Re: Chat Funktion
23. Jul 2008, 14:00
SERVER:
Delphi-Quellcode:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
serversocket1.Active := false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
serversocket1.Active:= true;
panel1.Color:=cllime;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
serversocket1.Active:= false;
panel1.Color:=clred;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ShellExecute( Handle, ' OPEN', ' http://wieistmeineip.de', nil, nil, SW_SHOWNORMAL)
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var text: string;
begin
text:= form1.ClientSocket1.socket.ReceiveText ;
memo1.Lines.Add(' Host: '+text+' ');
end;
end.
CLIENT:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
clientsocket1.Address:= edit1.Text;
clientsocket1.port := strtoint(edit2.Text)//der richtige port ist auf der anderen seite eingestellt
clientsocket1.Active:= true;
if clientsocket1.Active = true then button1.Font.Color:= cllime;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
edit1.Color:= cllime;
groupbox1.Enabled:=true; // wird grün, weil er connected ist
end;
procedure TForm1.ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
begin
edit1.Color:= clyellow;
end;
procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ErrorCode:= 0;
MessageDlg('Cannot connect to Server!', mtError, [mbOk], 0);
edit1.Color:= clwindow;
end;
procedure TForm1.ChatClick(Sender: TObject);
var text:string;
begin
text:=edit5.Text;
memo1.Lines.Add('Client: '+text+'');
form1.ServerSocket1.Socket.SendText(edit5.text);
end.
|
|
Zitat
|