|
-
Sep 2nd, 2001, 01:46 PM
#1
Thread Starter
Fanatic Member
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
-
Sep 2nd, 2001, 02:15 PM
#2
Frenzied Member
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.
-
Sep 2nd, 2001, 02:17 PM
#3
Thread Starter
Fanatic Member
k here.
VB Code:
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
-
Sep 2nd, 2001, 02:34 PM
#4
Fanatic Member
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]
-
Sep 2nd, 2001, 03:16 PM
#5
Thread Starter
Fanatic Member
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.
-
Sep 2nd, 2001, 05:26 PM
#6
Fanatic Member
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? 
-
Sep 2nd, 2001, 05:39 PM
#7
Fanatic Member
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]
-
Sep 2nd, 2001, 06:50 PM
#8
Thread Starter
Fanatic Member
actually i got that code of this website. but i dont have a problem with starting the file transfer code part from scratch.
-
Sep 4th, 2001, 10:17 AM
#9
Registered User
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
-
Sep 4th, 2001, 10:49 AM
#10
Registered User
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
-
Sep 4th, 2001, 11:11 AM
#11
Thread Starter
Fanatic Member
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.
-
Sep 24th, 2001, 08:02 AM
#12
Registered User
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|