Results 1 to 12 of 12

Thread: need help doing Multiple Simultaneouis FILE TRANSFERS Usin Winsock. PLEEEEEEEESE Help

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746

    need help doing Multiple Simultaneouis FILE TRANSFERS Usin Winsock. PLEEEEEEEESE Help

    Heres the code i currently use. but when i try to send two files one stops going until the other finishes. Is there a way I can stop this?

    Option Explicit

    'You don't use this API function.
    'Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    'Dim lcounter As Long
    'Do this...
    Private lcounter As Long

    'Pass strFilename 'ByVal'
    Public Sub SendFile(ByVal strFileName As String, wins1 As winsock)

    'Use proper coding conventions. Use prefixes such as int, byt etc.
    'Use descriptive variable names.

    'Dim FreeF2 As Integer
    Dim intFreeFile As Integer
    'Dim LocData2() As Byte
    Dim bytTwoKB() As Byte
    'Dim LenData2 As Long
    Dim lngLen As Long
    'Dim sendloop2 As Long
    Dim lngCount As Long

    intFreeFile = FreeFile 'Get free file.

    Open strFileName For Binary As #intFreeFile 'Open file

    ReDim bytTwoKB(1 To 2048) As Byte 'Work in 2kb chunks
    lngLen = LOF(intFreeFile) 'Get length of file

    For lngCount = 1 To lngLen \ 2048 'Go through file

    Get #intFreeFile, , bytTwoKB 'Get data from the file nCnt is from where to start the get

    DoEvents 'Give some time.
    wins1.SendData bytTwoKB 'Send the chunk
    DoEvents 'Give some time.

    lcounter = lcounter + 1

    'Form a proper 'If Else' case.
    'If lCounter Mod 50 = 0 Then DoEvents
    If lcounter Mod 50 = 0 Then
    DoEvents
    End If

    'Always clarify the variable in a loop. 'Next' wont work if you have loops within loops...
    'Next

    Next lngCount


    If lngLen Mod 2048 <> 0 Then ' If there is any left over at the end

    ReDim bytTwoKB(1 To lngLen Mod 2048) As Byte 'Resize byte array.
    Get #intFreeFile, , bytTwoKB 'Get the chunk.

    DoEvents 'Give some time.
    wins1.SendData bytTwoKB 'Send the chunk
    DoEvents 'Give some time.

    End If

    Close #intFreeFile

    DoEvents

    End Sub

    'Use descriptive sub/function names...
    'ByRef is fine, as we may be dealing with large amounts of data.

    Public Function oPD(strData As String) As String
    MsgBox "used oPD"
    'Again, use descriptive variable names.
    'Dim TextC As String * 3
    Dim strFix3 As String * 3 'Fixed length string. 3 characters.
    Dim G As Long
    Dim lngLen As Long 'Length of data
    'Dim TextX As String
    Dim strOut As String 'Output string.
    'Dim x As Long
    Dim i As Long 'Counting variable.

    lngLen = Len(strData)

    'Generally, use letters i, j, k for counting variables... coders tradition.
    For i = 1 To lngLen
    strFix3 = Asc(Mid(strData, i, 1))
    strOut = strOut & strFix3
    Next i

    oPD = strOut

    End Function

    'Use descriptive sub/function names...
    Public Function rPD(Text As String) As String
    MsgBox "used rPD"
    'Again, use descriptive variable names.
    'Dim TextC As String * 3
    Dim strFix3 As String * 3 'Fixed length string. 3 characters.
    Dim G As Long
    Dim lngLen As Long 'Length of data
    'Dim TextX As String
    Dim strOut As String
    'Dim x As Long
    Dim i As Long 'Counting variable

    lngLen = Len(Text)

    For i = 1 To G
    'The Chr() function takes a long. Convert the expression using Clng.
    'First check if it is numeric.
    If IsNumeric(Trim(Mid(Text, i, 3))) = True Then
    strFix3 = Chr(CLng(Mid(Text, i, 3)))
    End If
    strOut = strOut & strFix3
    Next i

    rPD = strOut

    End Function

  2. #2
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    You should clean your code up beofer you post it. Get rid of all the commented out code and post it between [vbcode ] and [/vbcode ] (remove the space before the ] ) so it will retain formatting.

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746
    k here.
    VB Code:
    1. Option Explicit
    2.  
    3. 'You don't use this API function.
    4. 'Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    5.  
    6. 'Dim lcounter As Long
    7. 'Do this...
    8. Private lcounter As Long
    9.  
    10. 'Pass strFilename 'ByVal'
    11. Public Sub SendFile(ByVal strFileName As String, wins1 As winsock)
    12.  
    13. 'Use proper coding conventions. Use prefixes such as int, byt etc.
    14. 'Use descriptive variable names.
    15.  
    16. 'Dim FreeF2 As Integer
    17. Dim intFreeFile As Integer
    18. 'Dim LocData2() As Byte
    19. Dim bytTwoKB() As Byte
    20. 'Dim LenData2 As Long
    21. Dim lngLen As Long
    22. 'Dim sendloop2 As Long
    23. Dim lngCount As Long
    24.  
    25. intFreeFile = FreeFile 'Get free file.
    26.  
    27. Open strFileName For Binary As #intFreeFile 'Open file
    28.  
    29. ReDim bytTwoKB(1 To 2048) As Byte 'Work in 2kb chunks
    30. lngLen = LOF(intFreeFile) 'Get length of file
    31.  
    32. For lngCount = 1 To lngLen \ 2048 'Go through file
    33.  
    34. Get #intFreeFile, , bytTwoKB 'Get data from the file nCnt is from where to start the get
    35.  
    36. DoEvents 'Give some time.
    37. wins1.SendData bytTwoKB 'Send the chunk
    38. DoEvents 'Give some time.
    39.  
    40. lcounter = lcounter + 1
    41.  
    42. 'Form a proper 'If Else' case.
    43. 'If lCounter Mod 50 = 0 Then DoEvents
    44. If lcounter Mod 50 = 0 Then
    45. DoEvents
    46. End If
    47.  
    48. 'Always clarify the variable in a loop. 'Next' wont work if you have loops within loops...
    49. 'Next
    50.  
    51. Next lngCount
    52.  
    53.  
    54. If lngLen Mod 2048 <> 0 Then ' If there is any left over at the end
    55.  
    56. ReDim bytTwoKB(1 To lngLen Mod 2048) As Byte 'Resize byte array.
    57. Get #intFreeFile, , bytTwoKB 'Get the chunk.
    58.  
    59. DoEvents 'Give some time.
    60. wins1.SendData bytTwoKB 'Send the chunk
    61. DoEvents 'Give some time.
    62.  
    63. End If
    64.  
    65. Close #intFreeFile
    66.  
    67. DoEvents
    68.  
    69. End Sub
    70.  
    71. 'Use descriptive sub/function names...
    72. 'ByRef is fine, as we may be dealing with large amounts of data.
    73.  
    74. Public Function oPD(strData As String) As String
    75. MsgBox "used oPD"
    76. 'Again, use descriptive variable names.
    77. 'Dim TextC As String * 3
    78. Dim strFix3 As String * 3 'Fixed length string. 3 characters.
    79. Dim G As Long
    80. Dim lngLen As Long 'Length of data
    81. 'Dim TextX As String
    82. Dim strOut As String 'Output string.
    83. 'Dim x As Long
    84. Dim i As Long 'Counting variable.
    85.  
    86. lngLen = Len(strData)
    87.  
    88. 'Generally, use letters i, j, k for counting variables... coders tradition.
    89. For i = 1 To lngLen
    90. strFix3 = Asc(Mid(strData, i, 1))
    91. strOut = strOut & strFix3
    92. Next i
    93.  
    94. oPD = strOut
    95.  
    96. End Function
    97.  
    98. 'Use descriptive sub/function names...
    99. Public Function rPD(Text As String) As String
    100. MsgBox "used rPD"
    101. 'Again, use descriptive variable names.
    102. 'Dim TextC As String * 3
    103. Dim strFix3 As String * 3 'Fixed length string. 3 characters.
    104. Dim G As Long
    105. Dim lngLen As Long 'Length of data
    106. 'Dim TextX As String
    107. Dim strOut As String
    108. 'Dim x As Long
    109. Dim i As Long 'Counting variable
    110.  
    111. lngLen = Len(Text)
    112.  
    113. For i = 1 To G
    114. 'The Chr() function takes a long. Convert the expression using Clng.
    115. 'First check if it is numeric.
    116. If IsNumeric(Trim(Mid(Text, i, 3))) = True Then
    117. strFix3 = Chr(CLng(Mid(Text, i, 3)))
    118. End If
    119. strOut = strOut & strFix3
    120. Next i
    121.  
    122. rPD = strOut
    123.  
    124. End Function

  4. #4
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Red face Info.

    I understand your need for help, but please don't keep posting this. If someone is going to help, they will. There is no need to repeatedly post for help...

    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746
    i was hopin some super genius might log on. its not like i have more than one thread of the same thing on the page.

  6. #6
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Holy shizz man, that code is a mess... so what are you traying to do? Send a file over? Maybe we should start from scratch?
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  7. #7
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728
    Originally posted by invitro
    Holy shizz man, that code is a mess... so what are you traying to do? Send a file over? Maybe we should start from scratch?
    ...and thats after i attempted to debug it, and cleaned it up a little Go easy though. The guy has only been coding for a month or so...

    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746
    actually i got that code of this website. but i dont have a problem with starting the file transfer code part from scratch.

  9. #9
    Registered User
    Join Date
    Jul 2001
    Location
    israel
    Posts
    81

    winsock - filetransfer

    flamewavetech
    hey i saw that you know how to send a file using winsock , can you please send me the code of sending a file to a specific index on my winsock and how to get it from the user and create it as a file.

    10x

  10. #10
    Registered User
    Join Date
    Jul 2001
    Location
    israel
    Posts
    81

    winsock filetransfer


    flamewavetech:

    hey i need your help after seeing that you finaly "did it" i want to ask you to send me the code of sending a file and recieving it through winsock . that would help me alot

    10x

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2001
    Posts
    746
    sure. use the code in the begginin of this thread. put it in a a module. u may need to alter the code bit since i fooled around with it a bit trying to get multiple winsock file transfers to work. then call the senfile sub and specify the pathname and winsock to sendthe file. then have the recieving winsock recieve the data. make sure that u have it recieve the data as bytes. and have it put the data into #1 or whatever # you opened for binary. sorry if its unclear im not the expert. but if u look in the lists of projects on vb world ull find one that has winsock file transfer.

  12. #12
    Registered User
    Join Date
    Jul 2001
    Location
    israel
    Posts
    81
    test

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