Ver Mensaje Individual
  #1  
Antiguo 01-09-2005
AFilth AFilth is offline
Miembro
 
Registrado: ago 2005
Posts: 119
Reputación: 19
AFilth Va por buen camino
Question Problema con TCP/IP en aplicación simple¿?¿?Ayuda por favor!

Buenas, estoy teniendo problemas al intentar mandar mensajes desde un servidor a distintos clientes conectados a él.
Os cuento:

1. Ejecuto el programa q crea un servidor en un pto especificado en defaultport.

2. Conecto un cliente por telnet a la ip del server y a ese puerto. Hasta ahi todo bien, puedo mandar mensajes y aparecen al momento en el cliente.

3. Conecto un segundo cliente al server al mismo puerto. En ese momento empieza el problema. El programa en ejecucion se ralentiza muchiiiiisimo, va todo muy lento y aunque sigue funcionando es inviable. Esto con 2 clientes, en el momento q conecto mas la cosa va a peor.

Aqui dejo el codigo q es muy simple, a ver si alguien sabe a q puede ser debido este problema...

Muchas gracias y una saludo.

unit Unit1;
interface

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

type
TForm1 = class(TForm)
Servidor: TIdTCPServer;
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure ServidorExecute(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
procedure BroadcastMessage(TheMessage : String );
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.BroadcastMessage(TheMessage: String);
var
Count: Integer;
List : TList;
Msg : String;
begin
Msg := TheMessage;

List := Servidor.Threads.LockList;
try
for Count := 0 to List.Count -1 do
try
TIdPeerThread(List.Items[Count]).Connection.WriteLn(Msg);
except
TIdPeerThread(List.Items[Count]).Stop;
end;
finally
Servidor.Threads.UnlockList;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
BroadcastMessage(Edit1.Text);
end;

procedure TForm1.ServidorExecute(AThread: TIdPeerThread);
begin
//nada
end;

end.
Responder Con Cita