Results 1 to 3 of 3

Thread: Winsock File Transfer [Unresolved]

  1. #1

    Thread Starter
    Hyperactive Member Philly0494's Avatar
    Join Date
    Apr 2008
    Posts
    485

    Winsock File Transfer [Unresolved]

    I made a multi-user chat program in VB.Net using the WinSock 6.0 control.

    I now need to be able to transfer pictures from client to server and view them on the server. I do this by converting the Image to a Base64String, then send the string over the WinSock TCP connection.

    However, a single packet cannot nearly handle the entire picture. Data is cut off after about 4337 characters, and the entire picture is usually at least 250,000 characters.

    I made this function that sends file text over winsock, packet by packet.
    Code:
    Public Sub SendFileText(ByVal text As String, Optional ByVal interval As Integer = 3000)
            Dim cPack As String = ""
            If text.Length < interval Then
                Sock.SendData("SS|" & text)
            Else
                Do Until text = ""
                    cPack = text.Substring(0, interval)
                    Sock.SendData("SS|" & cPack)
                    text = text.Substring(interval)
                Loop
            End If
    End Sub
    I was hoping this would send the file text in parts, so i could then append them on the Server side and rebuild a file.
    However, this code behaves the same way as sending the entire file at once does.

    I've also noticed that when you try to send multiple packets quickly over a winsock connection that they append to each other, which could explain why this approach isnt working.

    Is there any way i can transfer a picture from client to server?

    Thanks,
    Philly0494
    Last edited by Philly0494; Jul 22nd, 2009 at 09:25 PM.

  2. #2
    Addicted Member reacen's Avatar
    Join Date
    Jul 2009
    Location
    c:\windows\system32\gdi32.dll
    Posts
    243

    Re: Winsock File Transfer [Unresolved]

    I Do this:

    Dim DATA as string '// DATA = The whole picture.

    Send it like this:

    Winsock1.senddata DATA & "[/END OF FILE]"


    And when you recive:

    Code:
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim DATA As String: Winsock1.GetData DATA, , bytesTotal
    
    Static BUFFER As String
    
    BUFFER = BUFFER & DATA
    
    If InStr(BUFFER, "[/END OF FILE]") Then
    
    '// Her you have the whole picture recived on (BUFFER)  :D
    MsgBox BUFFER
    
    End If
    
    End Sub
    Hope you get it ...
    DoEvents

  3. #3
    Addicted Member reacen's Avatar
    Join Date
    Jul 2009
    Location
    c:\windows\system32\gdi32.dll
    Posts
    243

    Re: Winsock File Transfer [Unresolved]

    VB.Net ? ooops, sorry the code is in VB6.0 ^^'
    DoEvents

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