Problemas con Socket

27/02/2006 - 14:48 por Cracks78 | Informe spam
Hola a todos,
tengo este codigo que lo que hace es leer las respuestas a los comandos FTP,
por lo que siempre retorna un string. El tema es que en cierto momento se
queda colgado en la linea:
bytes = clientSocket.Receive(buffer, buffer.Length, SocketFlags.None);

No sale de ahi, no da error no hace nada, esto lo hace luego de haber
transferido varios archivosy no es siempre la misma cantidad.
Gracias de antemano por la ayuda que puedan brindar!!

private string readLine()
{
System.Timers.Timer oT = new System.Timers.Timer();
while(true)
{
bytes = clientSocket.Receive(buffer, buffer.Length, SocketFlags.None);
mes += ASCII.GetString(buffer, 0, bytes);
if(bytes < buffer.Length || bytes == 0 )
{
break;
}
}
char[] seperator = {''};
string[] mess = mes.Split(seperator);
if(mes.Length > 2)
{
mes = mess[mess.Length-2];
}else{
mes = mess[0];
}
if ( mes.Length >= 3 )
{
if(!mes.Substring(3,1).Equals(" "))
{
return readLine();
}
}else{
return "";
}
string a = "";
if(debug)
{
for(int k=0 ; k < mess.Length - 1 ; k++ ){
a += mess[ k ];
}
return a;
}
contador -= 1;
return mes;
}
 

Leer las respuestas

#1 José Escrich
27/02/2006 - 16:47 | Informe spam
Cracks78,

Lo que puede estar ocurriendo es que el socket se este cerrando del lado
del servidor y por eso nunca te devuelve la respuesta, fijate de ajustarle
el timeout.

saludos,

José Escrich
jescrich (a) gmail.com
http://latincoder.com

C> Hola a todos,
C> tengo este codigo que lo que hace es leer las respuestas a los
C> comandos FTP,
C> por lo que siempre retorna un string. El tema es que en cierto
C> momento se
C> queda colgado en la linea:
C> bytes = clientSocket.Receive(buffer, buffer.Length,
C> SocketFlags.None);
C> No sale de ahi, no da error no hace nada, esto lo hace luego de haber
C> transferido varios archivosy no es siempre la misma cantidad.
C> Gracias de antemano por la ayuda que puedan brindar!!
C>
C> private string readLine()
C> {
C> System.Timers.Timer oT = new System.Timers.Timer();
C> while(true)
C> {
C> bytes = clientSocket.Receive(buffer, buffer.Length,
C> SocketFlags.None);
C> mes += ASCII.GetString(buffer, 0, bytes);
C> if(bytes < buffer.Length || bytes == 0 )
C> {
C> break;
C> }
C> }
C> char[] seperator = {''};
C> string[] mess = mes.Split(seperator);
C> if(mes.Length > 2)
C> {
C> mes = mess[mess.Length-2];
C> }else{
C> mes = mess[0];
C> }
C> if ( mes.Length >= 3 )
C> {
C> if(!mes.Substring(3,1).Equals(" "))
C> {
C> return readLine();
C> }
C> }else{
C> return "";
C> }
C> string a = "";
C> if(debug)
C> {
C> for(int k=0 ; k < mess.Length - 1 ; k++ ){
C> a += mess[ k ];
C> }
C> return a;
C> }
C> contador -= 1;
C> return mes;
C>

Preguntas similares