Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   [Pedido] Tutorial sobre chat con sockets. (https://www.clubdelphi.com/foros/showthread.php?t=51061)

wofox 05-12-2007 01:29:42

[Pedido] Tutorial sobre chat con sockets.
 
Hola, necesito aprender a crear un chat en sockets desde 0. Descargué algunos ya hechos pero no los entendí por lo que agradecería que alguien posteara un tutorial sobre cómo hacerlo paso a paso.
Muchas gracias, espero su colaboración.

egostar 05-12-2007 01:37:19

Cita:

Empezado por wofox (Mensaje 250460)
Hola, necesito aprender a crear un chat en sockets desde 0. Descargué algunos ya hechos pero no los entendí por lo que agradecería que alguien posteara un tutorial sobre cómo hacerlo paso a paso.
Muchas gracias, espero su colaboración.

Hola wofox bienvenido al club, te recomiendo que leas nuestra guia de estilo.

No nos dices que versión de delphi usas, pero hasta donde se, hay un ejemplo de chat en las versiones de delphi en la carpeta DEMOS.

No se si por ahi hay algún tutorial de eso que pides.

Salud OS

wofox 05-12-2007 19:32:42

Estoy usando Borland Delphi 7, muchas gracias por decirme donde está el chat ;) lo acabo de encontrar.
Espero visitar este foro muy seguido y poco a poco ir aprendiendo.
Gracias por la ayuda pero me gustaría que alguien me explicara el codigo comentándolo, les dejo el código:
Código:

constructor TClientDataThread.Create(CreateSuspended: Boolean);
begin
  inherited Create(CreateSuspended);
  FreeOnTerminate := true;
  ListBuffer := TStringList.Create;
end;

procedure TClientDataThread.Terminate;
begin
  ListBuffer.Free;
  inherited;
end;

procedure TClientDataThread.Execute;
begin
  Synchronize(synchAddDataToControl);
end;

procedure TClientDataThread.synchAddDataToControl;
begin
 TargetList.AddStrings(ListBuffer);
end;
//------------- end TClientDataThread impl -------------------------------------


procedure TForm1.btnActivateServerClick(Sender: TObject);
begin
  TcpServer1.LocalPort := edtLocalPort.Text;
  TcpServer1.Active := True;
end;       

procedure TForm1.btnSendClick(Sender: TObject);
var
  I: Integer;
begin
  TcpClient1.RemoteHost := edtRemoteHost.Text;
  TcpClient1.RemotePort := edtRemotePort.Text;
  try
    if TcpClient1.Connect then
      for I := 0 to memSend.Lines.Count - 1 do
      TcpClient1.Sendln(memSend.Lines[i]);
  finally
    TcpClient1.Disconnect;
  end;
end;

procedure TForm1.TcpServer1Accept(sender: TObject;
  ClientSocket: TCustomIpClient);
var
  s: string;
  DataThread: TClientDataThread;
begin
  // create thread
  DataThread:= TClientDataThread.Create(true);
  // set the TagetList to the gui list that you
  // with to synch with.
  DataThread.TargetList := memRecv.lines;

  // Load the Threads ListBuffer
  DataThread.ListBuffer.Add('*** Connection Accepted ***');
  DataThread.ListBuffer.Add('Remote Host: ' + ClientSocket.LookupHostName(ClientSocket.RemoteHost) +
  ' (' + ClientSocket.RemoteHost + ')');
  DataThread.ListBuffer.Add('===== Begin message =====');
  s := ClientSocket.Receiveln;
  while s <> '' do
  begin
    DataThread.ListBuffer.Add(s);
    s := ClientSocket.Receiveln;
  end;
  DataThread.ListBuffer.Add('===== End of message =====');

  // Call Resume which will execute and synch the
  // ListBuffer with the TargetList
  DataThread.Resume;

end;



La franja horaria es GMT +2. Ahora son las 18:09:40.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi