Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-07-2015
Avatar de ingabraham
ingabraham ingabraham is offline
Miembro
 
Registrado: ago 2007
Posts: 614
Poder: 17
ingabraham Va por buen camino
Question ReceiveText serversocket extenso

-buenas tardes

tengo un problema con la lectura en un socket, la cadena es muy extensa y no la obtengo completa.

Código Delphi [-]
procedure Tfrmmonitor.Socket1ClientRead(Sender: TObject; Socket: TCustomWinSocket);
 var lectura:string;
begin
    lectura :=socket.ReceiveText;
end;

delphi xe

componente : TServerSocket
__________________
Enseñar es la virtud de un sabio.
Responder Con Cita
  #2  
Antiguo 08-07-2015
Avatar de jeremiselxi
jeremiselxi jeremiselxi is offline
Miembro
 
Registrado: ago 2008
Posts: 199
Poder: 16
jeremiselxi Va por buen camino
Buenas tardes.

Que tan extenso es el string que estas enviando para recibir?

ya que lo que puedes hacer es algo parecido a esto.

Serversocket:

Código Delphi [-]

procedure TForm1.Button3Click(Sender: TObject);
var
cadena,subcadena1, subcadena2:string;

begin
cadena:='1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901  2345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901  234567890123456789012345678901234567890123456789';

if Length(cadena) >255 then
begin

    subcadena1:= copy(cadena,1,253);//253 porque se agregara dos valores para enviarlo al servidor.
    subcadena2:= copy(cadena,254,300);

    ServerSocket1.Socket.Connections[0].SendText('01'+subcadena1);

    ServerSocket1.Socket.Connections[0].SendText('02'+subcadena2);

end;
end;



y del lado del cliente puedes obtener esta información.

Código Delphi [-]
procedure TForm1.ClientSocket1Read(Sender: TObject;
  Socket: TCustomWinSocket);
var
cadena1, cadena2: string;
begin

if (copy(Socket.ReceiveText,1,2)='01') then
cadena1:=Socket.ReceiveText;

if (copy(Socket.ReceiveText,1,2)='02') then
cadena2:=Socket.ReceiveText;

memo1.Lines.Add(cadena1);
memo1.Lines.Add(cadena2);
//memo1.Lines.Add(Socket.ReceiveText)
end;
__________________
Cristo te ama, ven a d él, ya k te espera con los brazos abiertos. Dios te bendiga mucho
Responder Con Cita
  #3  
Antiguo 09-07-2015
Avatar de cesarsoftware
cesarsoftware cesarsoftware is offline
Miembro
 
Registrado: nov 2006
Posts: 241
Poder: 18
cesarsoftware Va por buen camino
Hola en lo que yo se, la cadena maxima en un socket es de 65536 bytes.
Puedes usar las funcione sendstream y recvstream (creo que se escriben asi) para recoger cualquier tamaño de cadena superiores a 65536

Un saludo.
__________________
Disfruta de la vida ahora, vas a estar muerto mucho tiempo.
Responder Con Cita
  #4  
Antiguo 09-07-2015
Avatar de ingabraham
ingabraham ingabraham is offline
Miembro
 
Registrado: ago 2007
Posts: 614
Poder: 17
ingabraham Va por buen camino
gracias jeremiselxi,

el problema es que la cadena la envia un programa externo al que no tengo acceso. la cual contiene un xml

Código:
'NEURALÙÌ'#1#0
'<?xml version="1.0" encoding="utf-8"?><infoplate><DateHour>2015-07-07T14:16:56.703</DateHour><Plate>FPN753</Plate><Confidence>98,30993</Confidence><Country>Colombia</Country><CountryID>202</CountryID><ProcTime>67</ProcTime><CamID>0</CamID><ImageLeft>597</ImageLeft><ImageTop>472</ImageTop><ImageWidth>133</ImageWidth><ImageHeight>51</ImageHeight><Path>c:\tmp\imgs\874A8E0A-C8A6-4D6A-9360-ADB09A3FCD69\20150707\1416568547946-000000-93143-FPN753.jpg</Path><DirectionVector>0</DirectionVector><imgSize>87985</imgSize><img>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyM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PYGqsgCn5elADc4q+FD6esij7p2k/yzWbya1dLjN1bXcC/eWPzAPUigZSfpWJd/6x/qa23PGaxLv/Wv/vUhmXL'...
__________________
Enseñar es la virtud de un sabio.
Responder Con Cita
  #5  
Antiguo 09-07-2015
Avatar de cesarsoftware
cesarsoftware cesarsoftware is offline
Miembro
 
Registrado: nov 2006
Posts: 241
Poder: 18
cesarsoftware Va por buen camino
¿Conoces el tamaño de la cadena en origen?
Si no puedes usar esta función e ir incrementado el buffer recibido
Código Delphi [-]
    if ioctlsocket(nSocket, FIONREAD , &InBuffer) = SOCKET_ERROR then
    begin
      case WSAGetLastError of
        WSANOTINITIALISED: ErrorString := 'A successful WSAStartup call must occur before using this function.';
        WSAENETDOWN: ErrorString := 'The network subsystem has failed.';
        WSAEINPROGRESS: ErrorString := 'A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.';
        WSAENOTSOCK: ErrorString := 'The descriptor s is not a socket.';
        WSAEFAULT: ErrorString := 'The argp parameter is not a valid part of the user address space.';
      end;
      Break;
    end;
    if InBuffer > 65536 then // 64k es el maximo rendimiento y el tamaño del array
      InBuffer := 65536;     // el resto quedara para la siguiente lectura
    // para detectar desconexion, no se puede comprobar si hay algo en buffer
    rxLen := recv(nSocket, RxBuffer, InBuffer, 0);
    if (rxLen = SOCKET_ERROR) or (rxLen = 0) then
    begin
      case WSAGetLastError of
        WSANOTINITIALISED: ErrorString := 'A successful WSAStartup call must occur before using this function.';
        WSAENETDOWN: ErrorString := 'The network subsystem has failed.';
        WSAEFAULT: ErrorString := 'The buf parameter is not completely contained in a valid part of the user address space.';
        WSAENOTCONN: ErrorString := 'The socket is not connected.';
        WSAEINTR: ErrorString := 'The (blocking) call was canceled through WSACancelBlockingCall.';
        WSAEINPROGRESS: ErrorString := 'A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.';
        WSAENETRESET: ErrorString := 'The connection has been broken due to the keep-alive activity detecting a failure while the operation was in progress.';
        WSAENOTSOCK: ErrorString := 'The descriptor is not a socket.';
        WSAEOPNOTSUPP: ErrorString := 'MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations.';
        WSAESHUTDOWN: ErrorString := 'The socket has been shut down; it is not possible to receive on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH.';
        WSAEWOULDBLOCK: ErrorString := 'The socket is marked as nonblocking and the receive operation would block.';
        WSAEMSGSIZE: ErrorString := 'The message was too large to fit into the specified buffer and was truncated.';
        WSAEINVAL: ErrorString := 'The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled or (for byte stream sockets only) len was zero or negative.';
        WSAECONNABORTED: ErrorString := 'The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.';
        WSAETIMEDOUT: ErrorString := 'The connection has been dropped because of a network failure or because the peer system failed to respond.';
        WSAECONNRESET: ErrorString := 'The virtual circuit was reset by the remote side executing a hard or abortive close. The application should close the socket as it is no longer usable.';// On a UPD-datagram socket this error would indicate that a previous send operation resulted in an ICMP "Port Unreachable" message.';
      else
        ErrorString := 'Error Desconocido';
        if RxLen = 0 then
          ErrorString := 'Desconectado';
      end;
      Break;
    end
    else
    begin
      if RxLen > 0 then
      begin
        ErrorString := '';
        Synchronize(recibido);
      end;
    end;
Un saludo.
__________________
Disfruta de la vida ahora, vas a estar muerto mucho tiempo.
Responder Con Cita
Respuesta



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

Temas Similares
Tema Autor Foro Respuestas Último mensaje
ClientSocket y ServerSocket ZayDun Internet 2 20-06-2011 14:38:57
Serversocket y Clientsocket Dragon Varios 3 03-05-2006 06:11:36
Pasar texto extenso por un formulario D-MO PHP 1 25-01-2006 07:30:36
ClientSocket / serverSocket VRO Varios 2 20-10-2005 18:46:51
¿Convertir los caracteres ASCII del ClientSocket.Socket.ReceiveText? Kamikaze Internet 23 14-07-2005 15:35:39


La franja horaria es GMT +2. Ahora son las 17:50:14.


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
Copyright 1996-2007 Club Delphi