Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2010, 09:40
Avatar de Nemutagk
Nemutagk
Colaborador
 
Fecha de Ingreso: marzo-2004
Ubicación: México
Mensajes: 2.633
Antigüedad: 21 años
Puntos: 406
Ayuda con Winsock!!!

Que tal compañeros, acudo a ustedes porque tengo problemas, veran, tengo un equipo que es desatendido (sin teclado, mouse ni monitor), vamos, un servidor casero que cicla una determinada secuencia de tareas, pero como me era mucho trabajo estar conectado el vnc desde equipos que no tengo instalado el vnc estoy desarrollando una pequeña aplicacion para tomar una screenshot del escritorio del servidor y mandarla a una aplicacion cliente cada determinado tiempo y asi poder verificar el estado del equipod desde una pagina en internet, ahora, ya tengo "casi" todo, mi problema es que cuando manda la imagen al cliente esta llega incompleta (no llegan todos los bytes...) y no entiendo que es lo que estoy haciendo mal, si alguien es tan amable de checar el codigo y ver que problema hay se lo agradeceria mucho

Este es el codigo del cliente (el que envia la imagen)
Código vb:
Ver original
  1. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  2.     Dim Buffer As String
  3.     Winsock1.GetData Buffer
  4.     estado.Text = estado.Text + vbCrLf + "Comando: " + Buffer
  5.     estado.SelStart = Len(estado.Text)
  6.     comandos (Buffer)
  7. End Sub
  8.  
  9. Public Function comandos(comando As String)
  10.     If comando = "screenshot" Then
  11.         Picture1.Picture = CaptureScreen()
  12.         SavePicture Picture1.Picture, "c:\screenshot.bmp"
  13.         urlFile.Text = "C:\screenshot.bmp"
  14.         Open urlFile.Text For Binary As #1
  15.             Winsock1.SendData "EMA" & urlFile.Text & "LAR" & LOF(1)
  16.             peso.Text = LOF(1)
  17.         Close #1
  18.        
  19.         On Error GoTo ema
  20.         Dim Buf As String * 1024
  21.         Dim Todo As String
  22.        
  23.         Open urlFile.Text For Binary As #1
  24.             barra.Min = 0
  25.             barra.Max = LOF(1)
  26.             Do While Not EOF(1)
  27.                 DoEvents
  28.                 Get #1, , Buf
  29.                 Todo = Todo & Buf
  30.                 If Len(Todo) <= barra.Max Then barra.Value = Len(Todo)
  31.             Loop
  32.         Close
  33.        
  34.         Winsock1.SendData Todo
  35.         estado.Text = estado.Text & vbCrLf & "Enviando archivo " & Len(Todo) & " bytes..."
  36.         estado.SelStart = Len(estado.Text)
  37.        
  38.         Exit Function
  39. ema:
  40.         MsgBox Err.Description
  41.     End If
  42. End Function
  43.  
  44. Public Function sendfile(txt As String)
  45.      On Error GoTo ema
  46.     Dim Buf As String * 1024
  47.     Dim Todo As String
  48.    
  49.     Open urlFile.Text For Binary As #1
  50.         barra.Min = 0
  51.         barra.Max = LOF(1)
  52.         Do While Not EOF(1)
  53.             DoEvents
  54.             Get #1, , Buf
  55.             Todo = Todo & Buf
  56.             If Len(Todo) <= barra.Max Then barra.Value = Len(Todo)
  57.         Loop
  58.     Close
  59.    
  60.     Winsock1.SendData Todo
  61.    
  62.     Exit Function
  63. ema:
  64.     MsgBox Err.Description
  65.      
  66. End Function

Y este es el codigo del servidor (el que recibe la imagen)
Código vb:
Ver original
  1. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  2.     Dim Texto As String
  3.    
  4.     Winsock1.GetData Texto
  5.    
  6.     If Mid(Texto, 1, 3) = "EMA" Then
  7.         infoarchivo (Texto)
  8.         Exit Sub
  9.     End If
  10.    
  11.     If Mid(Texto, 1, 3) = "LAR" Then
  12.         'Frame1.Caption = "Archivo : " & Mid(Texto, 4, Len(Texto) - 3) & " bytes."
  13.        Largo = CLng(Mid(Texto, 4, Len(Texto) - 3))
  14.         Exit Sub
  15.     End If
  16.    
  17.     Archivo = Archivo & Texto
  18.    
  19.     If Len(Archivo) >= Largo Then
  20.         Common.DialogTitle = "Guardar archivo..."
  21.         Common.FileName = nameFile.Caption
  22.         Common.ShowSave
  23.         Open Common.FileName For Binary As #1
  24.             Put #1, , Archivo
  25.             Largo = 0
  26.             Archivo = ""
  27.         Close #1
  28.     End If
  29. End Sub
  30.  
  31. Public Function infoarchivo(txt As String)
  32.     Dim i As Long
  33.     Dim Nom As String
  34.     txt = Mid(txt, 4, Len(txt) - 3)
  35.     For i = 1 To Len(txt)
  36.         If Mid(txt, i, 3) = "LAR" Then
  37.             Nom = Left(txt, i - 1)
  38.             Largo = CLng(Mid(txt, i + 3, Len(txt) - i))
  39.             nameFile.Caption = Nom
  40.             sizeFile.Caption = Largo
  41.             estado.Text = estado.Text & vbCrLf & "Archivo : " & Largo & " bytes..."
  42.         End If
  43.     Next i
  44. End Function

De antemano les agradesco todo la ayuda que me puedan brindar
__________________
Listo?, tendría que tener 60 puntos menos de IQ para considerarme listo!!!
-- Sheldon Cooper
http://twitter.com/nemutagk
PD: No contestaré temas vía mensaje personal =)