Results 1 to 3 of 3

Thread: Winsocks

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    3

    Question Winsocks

    First of all, I think it`s important to point out I`m no expert in VB. So bare with me.

    I´m writting a code for a remote file manager. I`ve got the file transfer to work but my problem is in the explorer itself.

    My basic idea is to have a FileListBox with all the files in the server side and, on request by the client, with a For i = 0 To Files1.ListCount - 1 make a run over each file and send them to the client. Then, on the client side, add each file name (separating them with a "|") one by one to a ListBox with a split function.

    Here is the code:

    Server Side:

    Code:
    Case "1"
        For i = 0 To Files1.ListCount - 1
            x = Files1.List(i) & "|" & x       
        Next i
    Winsock1.SendData "File" & x
    Client Side:

    Code:
    Case "File"
    Y = Right(Y, Len(Y) - 4)
    
    Dim fields() As String
    fields() = Split(Y, "|")
    
    For i = 0 To UBound(fields)
        List1.AddItem Trim$(fields(i))
    Next
    End If
    First, I would like to point out:

    *This might not the the most eficient way to achieve my objective, BUT I`m trying to learn and understand why the code is not working.

    Now the questions:

    1-Why do I get the last 96 characters from all the file names? (I am almost sure it has something to do with the buffer of the winsock)
    2-I know a timer could fix this but, is it the only way?

    Thank you in advance!

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Winsocks

    I wrote a remote file manager but it was like 5 years ago and I think there's a couple small bugs and if I were to do it today I'd do it differently. Not sure if it will help or not:
    http://www.pscode.com/vb/scripts/Sho...50253&lngWId=1

    What does your whole data arrival event look like?

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    3

    Re: Winsocks

    Hey DigiRev! Your remote file manager was one of the first things I got a hold on when I started coding this. I found it a little bit complex for my level, but I`m trying to understand how it works. Now, here is my data arrival:

    On server side:
    Code:
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim Y As String
    Dim X As String
    
    Winsock1.GetData X, vbString
    Y = Right(X, 100)
    X = Left(X, 1)
    
    Select Case X
    
    Case "1" ' This is for files
        For i = 0 To Files1.ListCount - 1
            x = Files1.List(i) & "|" & x       
        Next i
    Winsock1.SendData "File" & x
    
    Case "2" ' This is for folders
        For i = 0 To Dire.ListCount - 1
            x = Dire.List(i) & "|" & x       
        Next i
    Winsock1.SendData "Dire" & x
    
    End Select
    
    End Sub
    On the client side:

    Code:
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim X As String
    Dim Y As String
    Dim Z As String
    
    Winsock1.GetData X, vbString
    
    Y = Right(X, 100) 'Divido la informacion de X
    Z = Left(X, 4) ' Separo el primer string para el select case
    
    Select Case Z
    
    Case "Dire"
    Y = Right(Y, Len(Y) - 4)
    
    Dim fields() As String
    fields() = Split(Y, "|")
    
    For i = 0 To UBound(fields)
        List2.AddItem Trim$(fields(i))
    Next
    End If
    
    Case "File"
    Y = Right(Y, Len(Y) - 4)
    
    Dim fields() As String
    fields() = Split(Y, "|")
    
    For i = 0 To UBound(fields)
        List1.AddItem Trim$(fields(i))
    Next
    End If
    
    End Select
    
    End Sub
    Thanks again for the help!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width