Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Colaboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 25-04-2004
Avatar de Sr_Sombrero
Sr_Sombrero Sr_Sombrero is offline
Miembro
 
Registrado: may 2003
Posts: 49
Poder: 0
Sr_Sombrero Va por buen camino
Lo probé y me pone el nombre de mi pc, aunque lo de AThread ya es un comiezo

¿Se puede poner en el caption directamente el Thread que identifica a cada conexió? (Para no tener que meterme con los apuntadores). ¿Si es así como se pone?.

Gracias por ayudarme
Responder Con Cita
  #2  
Antiguo 25-04-2004
Avatar de jachguate
jachguate jachguate is offline
Miembro
 
Registrado: may 2003
Ubicación: Guatemala
Posts: 6.254
Poder: 30
jachguate Va por buen camino
El caption es una propiedad de tipo string. El thread es un objeto de tipo TidPeerThread.

En conclusión: El thread no puede ponerse como caption, por razones obvias. Asi, que a meterse con los apuntadores... que no es tan complicado al fin de cuentas. Ya cada elemento del ListView (de tipo TListItem) incorpora una propiedad data que es un apuntador genérico. Solo hace que apunte al thread, y listo.

Hasta luego.

__________________
Juan Antonio Castillo Hernández (jachguate)
Guía de Estilo | Etiqueta CODE | Búsca antes de preguntar | blog de jachguate
Responder Con Cita
  #3  
Antiguo 26-04-2004
Avatar de Sr_Sombrero
Sr_Sombrero Sr_Sombrero is offline
Miembro
 
Registrado: may 2003
Posts: 49
Poder: 0
Sr_Sombrero Va por buen camino
Seguiré tu consejo, tengo unos pdf sobre el tema.

Gracias !!!
Responder Con Cita
  #4  
Antiguo 20-05-2004
Avatar de Sr_Sombrero
Sr_Sombrero Sr_Sombrero is offline
Miembro
 
Registrado: may 2003
Posts: 49
Poder: 0
Sr_Sombrero Va por buen camino
Luego de tomar distancia del proyecto volver logré hacerlo funcionar y sin usar los INDY.
Lo he probado a fondo y anda muy bien, aunque con las INDY tal vez hubiera quedado más prolijo.
Acá les dejo la solución por si a alguien le sirve.

Usando Socket.RemoteAddress te devuelve un entero que es el sock y que es único por cada conexión.


Código:
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
var
ali: TListItem;
strIndex: string;
begin

  aLi := ListView1.Items.Add;
  with aLi do
     begin
      Caption:= IntToStr(Socket.SocketHandle);
      SubItems.Add(Socket.RemoteAddress);
      SubItems.Add('');
      SubItems.Add('');
      SubItems.Add('');
      SubItems.Add('');
      SubItems.Add('');
      SubItems.Add('');
end;
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
  var
lvItem: TListItem;
s: string;

begin
// GetToken es una funcion para separ el texto que llega al socket
s:= Socket.ReceiveText;

if copy(s,1,7)='details' then begin
lvItem:= ListView1.FindCaption(0,intToStr(Socket.SocketHandle),true,true,false);
  if lvItem <> nil then begin
  lvItem.SubItems[1]:=(GetToken(S,';',2));
  lvItem.SubItems[2]:=(GetToken(S,';',3));
  lvItem.SubItems[3]:=(GetToken(S,';',4));
  lvItem.SubItems[4]:=(GetToken(S,';',5));
  lvItem.SubItems[5]:=(GetToken(S,';',6));
  lvItem.SubItems[6]:=(GetToken(S,';',7));
  end;
  end;
end;

procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
var
lvItem: TListItem;
begin
//busca el sock que se desconectó y la elimina de la lista
lvItem:=ListView1.FindCaption(0,intToStr
Socket.SocketHandle),true,true,false);
if lvItem <> nil then
lvItem.Delete;
end;

//esto es para enviar un comando al cliente desde la Listview
// sabiendo el sock y no el numero de conexión

procedure TForm1.Connect1Click(Sender: TObject);
var
intNumConnect, intSocket: integer;
begin
intNumConnect:=-1;

if listView1.ItemIndex = -1 then begin
    showmessage('There is no server selected');
    exit;
   end
   else
   begin
   intSocket:= StrToInt(listView1.Selected.Caption);
   repeat
   intNumConnect:= intNumConnect + 1;
   if
   ServerSocket1.Socket.Connections[intNumConnect].SocketHandle=IntSocket then
   ServerSocket1.Socket.Connections[intNumConnect].SendText('connect');
   until
   (intNumConnect + 1) = ServerSocket1.Socket.ActiveConnections;
   end
end;
Saludos

Última edición por Sr_Sombrero fecha: 20-05-2004 a las 22:17:01.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 06:44:51.


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