Results 1 to 5 of 5

Thread: Winsock - Transfer File

  1. #1

    Thread Starter
    Member LoopUntil's Avatar
    Join Date
    Jul 2008
    Posts
    58

    Winsock - Transfer File

    I'm trying to transfer a simple file between a client and a server but It doesnt work... The sended file (ceta1.exe) must be 16kb but Its only 8kb.

    I tryed to debug and I saw that the server use the Put function only 2 times.

    What can be the problem?!


    CLIENT:

    Code:
    Private Sub Command1_Click()
    Winsock1.Close
    Winsock1.Connect Text1.Text, Text2.Text
    End Sub
    
    Private Sub Command2_Click()
    Dim datatosend As String
    Dim conteggio As Long
    
    datatosend = Space(4000)
    
    Open Text3.Text For Binary As #1
    For conteggio = 0 To CLng(LOF(1) / 4000)
    Get #1, conteggio * CLng(4000) + 1, datatosend
    Winsock1.SendData datatosend
    Next conteggio
    Close #1
    
    End Sub
    
    Private Sub Command3_Click()
    cmn1.ShowOpen
    Text3.Text = cmn1.FileName
    End Sub
    
    
    Private Sub Form_Load()
    Text1.Text = Winsock1.LocalIP
    End Sub

    SERVER:

    Code:
    Private Sub Form_Load()
    Winsock1.Listen
    End Sub
    
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock1.Close
    Winsock1.Accept requestID
    End Sub
    
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim data As String
    
    Winsock1.GetData data
    
    Open "C:\ceta1.exe" For Binary As #1
    Put #1, , data
    Close #1
    End Sub


    P.S. I know that there are a lot of topics and sources on the forum about this but I want to do it by myself because the other programs are too complicated
    Last edited by LoopUntil; Aug 2nd, 2008 at 09:26 AM.

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Winsock - Transfer File

    What version of VB are you using?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Member LoopUntil's Avatar
    Join Date
    Jul 2008
    Posts
    58

    Re: Winsock - Transfer File

    Quote Originally Posted by chris128
    What version of VB are you using?
    VB 6.0 , you can see it in my profily anyway xD

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Winsock - Transfer File

    Quote Originally Posted by LoopUntil
    VB 6.0 , you can see it in my profily anyway xD
    lol sorry, I (like most people) dont check out the profile of every person that asks a question :P
    I'm afraid I cant really help though cos I've only used VB.NET, not Vb6. Sorry, hope someone else can help you out.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Winsock - Transfer File

    Your sending loop is incorrect. For a 4000 byte file you'll try to do two 4000 byte reads. You should also do a sequential (not random) read in the loop.

    You also need to deal with a final chunk < 4000 bytes.

    Your receive logic is incorrect. It accepts one received data segment and then gives up. Typically these are about 8K bytes when receiving a steady stream. You have to receive/write in chunks as they arrive, until the final chunk.

    You have provided no method to determine when a final chunk has arrived.

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