Page 1 of 3 123 LastLast
Results 1 to 40 of 86

Thread: VB - How to send a file using the Winsock control

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    VB - How to send a file using the Winsock control

    I made 2 projects: ClientSend and ServerReceive

    You can send files of ANY size with this (well actually any file less than 2GB).

    First start the Server program, click on the "Start Listening for Connections" button.
    Then start the client, choose a file you want to transfer, then click on "Send File"

    The server supports multiple connections, so you can open more than one Client application and transfer more than one file.
    Both of them show the progress of the transfer.
    The server saves the files in its App.Path directory.

    I tried to make it as simple as possible, and I did not put any comments.
    I have a few comments, but that's because I copied and pasted some code from my other applications.

    Anyways... enjoy... and I hope you learn something from it.
    Attached Files Attached Files
    Last edited by CVMichael; Dec 21st, 2005 at 01:34 PM. Reason: Some spelling mistakes

  2. #2
    New Member
    Join Date
    Nov 2006
    Posts
    9

    Re: VB - How to send a file using the Winsock control

    Hi, the speed seems to be limited to 256 KB/s. How could we increase the speed??

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Try increasing the packet size in the client, the first line in the form:
    VB Code:
    1. Private Const PacketSize As Long = 1024 * 4
    That is 4K per packet, make it 8 or 16 (or even more)

    By the way, you have an internet connection that is THAT fast ? must be a T1 or something... I wish I had my internet that fast...

  4. #4
    Hyperactive Member BrendanDavis's Avatar
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    492

    Re: VB - How to send a file using the Winsock control

    Quote Originally Posted by CVMichael
    Try increasing the packet size in the client, the first line in the form:
    VB Code:
    1. Private Const PacketSize As Long = 1024 * 4
    That is 4K per packet, make it 8 or 16 (or even more)

    By the way, you have an internet connection that is THAT fast ? must be a T1 or something... I wish I had my internet that fast...
    I have a cable modem and I've uploaded as fast as 500+ kb/s, downloaded as fast as 1.5+ mb/s. It's not that uncommon, as far as I know.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Yea, I have cable modem too but it's 128 KBits / second Upload and 1 MBit/second download.

    If you notice the values are in Bits, so you have to divide by 8 to get Bytes...
    So really it's 16 KBytes/second upload, and 128KBytes/second download.

    My program shows the speed in KBytes / second...

  6. #6
    New Member
    Join Date
    Nov 2006
    Posts
    9

    Re: VB - How to send a file using the Winsock control

    You have 1 Mbit/s. 256KB/s is just the double of yours...

    Yeah, thats right. Today almost everyone in a "1st-world country" has got at least DSL.
    Actually i have unfortunately just 384 kbit/s (48 KB/s) because my (DS)-Line is much too long (over 50 db). That really isn't fast.
    I reached the 256 KB/s on my local Computer.

    Watch it yourself:

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    That is KBytes/Second, so you reached 1984 KBytes / second that is 31,744 KBits / second !!!!

    The program shows the speed in KBytes / second !

    You divided KBytes by 8, but it already shows in KBytes...
    Attached Images Attached Images  

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    And by the way, about this:
    VB Code:
    1. Private Const PacketSize As Long = 1024 * 31
    You are wondering why you cannot multiply by 32 ?
    That's because 1024 is taken as Integer by the compiler, and 32 is also an integer, so if you multiply them together you also get integer type, but you get an overflow error, right ?

    The solution is simple, comvert the numbers to Long type, like this:
    VB Code:
    1. Private Const PacketSize As Long = 1024[B]&[/B] * 64[B]&[/B]  ' 64 KBytes buffer
    Or if you just type in the total number (multiplied), then it will automatically convert it to long type
    VB Code:
    1. Private Const PacketSize As Long = 65536  ' 64 KBytes buffer

  9. #9
    New Member
    Join Date
    Nov 2006
    Posts
    9

    Re: VB - How to send a file using the Winsock control

    Quote Originally Posted by CVMichael
    That is KBytes/Second, so you reached 1984 KBytes / second that is 31,744 KBits / second !!!!

    The program shows the speed in KBytes / second !

    You divided KBytes by 8, but it already shows in KBytes...
    No, I divided nothing.
    1984/8= 248, My speed at the beginning was 256 Kbyte/s



    The picture shows the speed AFTER my modification.
    Before, the speed was 2048 Kilobit/s = 256 Kilobyte/s = 0,256 Megabyte/s = 0.000256 Gigabyte/s. Just to make sure that i know these things.

    The hint with the "&" works fine! But the speed won't go over 10.000 kbyte/s
    Last edited by DrGonzo; Nov 1st, 2006 at 09:44 AM.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    OMG, you have to learn your limits.... first of all, how on earth could you send 10 MBytes / second on a real internet connection ? Why would you want to transfer a file from your comptuer to the same comptuer using Winsock.... why not just copy & paste the file the regular way ?

    And also, you said it won't go over 10 MBytes / sec ? well, do this:
    Copy a file from a directory to another (on the same hard drive), and the speed won't be much faster than that...
    The hard drive has to read 10 MBytes / second, and it has to write the same 10 MBytes back to the same hard drive, so your computer has to handle 20 MBytes / second !

    Stop testing this on a local computer, and use a real internet connection ! and then you don't need to make the buffer that big because it cannot transfter that much anyways because of internet limitations....

  11. #11
    New Member
    Join Date
    Nov 2006
    Posts
    9

    Re: VB - How to send a file using the Winsock control

    I've just tested the program. I'm now not going to use it for any file i will copy on my computer.
    Did i anoy you with any of the above written? English isn't my mother tongue.


  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    The program is supposed to be used for transfering files over the internet (or network)...

    Yea, you got me a little anoyed... but it's OK... from your previous screen shot, I see you are from Germany (or maybe I got it wrong ?)

  13. #13
    New Member
    Join Date
    Nov 2006
    Posts
    9

    Re: VB - How to send a file using the Winsock control

    Yes I'm from germany. Could you please write into a PM what was the annoying part...? thx

  14. #14
    Member
    Join Date
    Dec 2006
    Location
    Ontario, Canada
    Posts
    32

    Re: VB - How to send a file using the Winsock control

    I get the runtime error 70 which is Permission denied on this line of code

    VB Code:
    1. Open App.Path & "\" & Clients(Index).FileName For Binary Access Write Lock Write As Clients(Index).FileNum

    Any idea's?

    It's on frmReceive, the file server under the DataArrival Sub

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    If it's a Permission denied error, then there is nothing I can do/change in the program to fix that... only you can, by setting the appropriate permissions to the directory where you have the application

  16. #16
    Hyperactive Member BrendanDavis's Avatar
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    492

    Re: VB - How to send a file using the Winsock control

    Quote Originally Posted by CVMichael
    Yea, I have cable modem too but it's 128 KBits / second Upload and 1 MBit/second download.

    If you notice the values are in Bits, so you have to divide by 8 to get Bytes...
    So really it's 16 KBytes/second upload, and 128KBytes/second download.

    My program shows the speed in KBytes / second...
    You have one slow cable modem, then I topped mine out downloading off a good server at just over 2mb/s. I downloaded a 20 MB file in less than 10 seconds, in other words.

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Quote Originally Posted by BrendanDavis
    You have one slow cable modem, then I topped mine out downloading off a good server at just over 2mb/s. I downloaded a 20 MB file in less than 10 seconds, in other words.
    How much do you pay per month ?

    I can choose to have higher speed from my provider if I pay more (of course), I think the highest is about the speeds you just mentioned, but is aproximatelly $60 (Canadian $) here. Now I'm paying $30 per month.

  18. #18

    Re: VB - How to send a file using the Winsock control

    Hey I've modified your code and it became more effective in sending. you don't need to increase packet size to send faster. I've disabled the timer and found a workaround. Replace your SendComplete event with this:

    VB Code:
    1. Private Sub SckSendFile_SendComplete()
    2.    
    3.     'Finish off the send complete first with DoEvents, then immediately send the data
    4.     DoEvents
    5.     Call tmrSendFile_Timer 'Send the data
    6.    
    7. End Sub

    It have just used "DoEvents" rather than the timer. You should find that it sends a lot faster on fast networks like LAN (not limited to 256 KB/s) and does not need a timer. It should be only slightly faster over slower connections. The "DoEvents" really did work well for me.
    Last edited by evan29; Feb 11th, 2007 at 07:12 AM.

  19. #19
    New Member
    Join Date
    Nov 2006
    Posts
    9

    Re: VB - How to send a file using the Winsock control

    Hi!

    I just wanted to say that nowadays in big cities for example here in germany like cologne or stuttgart VDSL with an effective download data rate of 50 Mbit/s (that are 6,25 Mb/s) and an upload data rate of 10 Mbit/s are very common. These cost 50 euro or 75 C $.

    But even in german villages you can get ADSL or even ADSL2 and ADSL2+ with data rates up to 25 Mbit/s (3,125 Mb/s).

  20. #20
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Re: VB - How to send a file using the Winsock control

    but this program of the one to send of a person for the other???
    What are in different places???
    Please they answer.

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Quote Originally Posted by Pedromiba
    but this program of the one to send of a person for the other???
    What are in different places???
    Please they answer.
    What ?

    I need a translator to propper English here...

  22. #22
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Re: VB - How to send a file using the Winsock control

    I'm sorry i don't speak English very well!! LOL
    I with the presented program can send filing-cabinets for other people?

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    "filing-cabinets" ??

    If those "filing-cabinets" are files, then I don't see the problem... the program sends any file, regardless of the type

  24. #24
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Re: VB - How to send a file using the Winsock control

    my problem is not this. my problem is:
    “with this program, I can send filing-cabinets of a computer for another one??”

  25. #25
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Re: VB - How to send a file using the Winsock control

    filing-cabinets = Files

  26. #26
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Re: VB - How to send a file using the Winsock control

    my problem isn't that. my problem is :
    ""with this program can i send files of a computer for another one??"

  27. #27

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Yes you can... did you actually try it ?

    But please don't post every minute, you can edit your posts, and make corrections if you need to.

  28. #28
    New Member
    Join Date
    Jun 2007
    Posts
    6

    Re: VB - How to send a file using the Winsock control

    I try.
    but i can't send files for other pc's.
    how i do this????

  29. #29

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Let's say you are a car repair man, and someone comes to you and tells you fix my car, it does not work... will you know what to fix ? will you know where to even start checking ?
    But if if he tells you that the back right lights are not working, then you know where to start looking for problems, right ?

    So... if you just tell me "i can't send files", how do you think I'll know where the problem is ?
    And besides that... programs don't work the same way on every computer... a lot of things can iterfere with the program, firewall, router, antivirus, operating system, etc...

    What did you try ?
    What works, and what does not work ?
    Tell me something usefull !

    If you continue to ask for help like this... then it will take a hell of a lot of time to get your problem solved !

  30. #30
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Anchorage, Alaska
    Posts
    545

    Re: VB - How to send a file using the Winsock control

    Just wondering, why is your file size for the program limited to 2gb? I know I would never download or transfer that much, I'm just wondering.
    Please RATE posts, click the RATE button to the left under the Users Name.

    Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.


    "As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood

  31. #31

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Because it's using a Long data type to keep track of stransfer size.

    A long has a maximum of 2 GBytes (2^31 = 2,147,483,648)

    Change the variable type to Double, and you can transfer Terabytes of data...

  32. #32
    Hyperactive Member BrendanDavis's Avatar
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    492

    Re: VB - How to send a file using the Winsock control

    Quote Originally Posted by CVMichael
    How much do you pay per month ?

    I can choose to have higher speed from my provider if I pay more (of course), I think the highest is about the speeds you just mentioned, but is aproximatelly $60 (Canadian $) here. Now I'm paying $30 per month.
    I pay $40 a month US. Don't know how much that is Canadian (even though I used to live there, lol). i think the exchange rate these days is .97 / dollar, or at least it was a week or two ago. so it's not THAT much more in canadian.
    God put me on this earth to do many great things, and I'm so far behind that I'm going to live forever.

    I'm programming for Windows using a Apple Mac Mini, 1.5Ghz with 512MB DDR RAM. I feel like I'm committing a crime :P

  33. #33
    New Member
    Join Date
    Jul 2007
    Posts
    1

    Re: VB - How to send a file using the Winsock control

    Just wondering if you had any thoughts on how to transfer multiple files to the server

    Thanks...

  34. #34

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Well, the server acceps more than 1 client, so send the files with more than one client...

    Or, modify the client so that when it's done sending the current file, to load another file from a list, and send that one, and so on...

  35. #35
    New Member
    Join Date
    Sep 2007
    Posts
    3

    Re: VB - How to send a file using the Winsock control

    Hi CVMichael,

    for couples of weeks i have been trying to write a client/server application (1 server with multi-clients) which can send and receive files (bidirectional).
    without success, until today i land on your article on this great site. my problem was to handle more than one client while sending/receiving files, but with ur example code i think my life become a bit easier, i will ask for help just in case i'm having difficulties.

    pp
    Last edited by ppitta; Sep 17th, 2007 at 08:27 AM.

  36. #36
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: VB - How to send a file using the Winsock control

    The coding is really amazing....but Im trying to do the other way around...

    Is there anyway I can use this code to send file from one server to multiple clients instead from multiple clients to one server...actually I have connected multiple printing machines to a server and all the production files I would like to transfer from a server thru network. Total Clients I have 5 and I will be transferring multiple files to each machine. The size of the files will be 25 MB to 50 MB and I got attracted by your code since it can transfer any size of file.

    Any help?
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  37. #37

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    If you transfer through local network, then there is a much better solution...

    Right now, (if you reverse), when you send a file that is 50 MBytes * 5 times, that will be 250 MBytes sent over the network.

    But... if you use UDP connection, you can broadcast the file to ALL computers at the same time, therefore if you send 50 MB to 5 clients, you are sending only 50 MBytes over the network ! You don't even have to specify the target computer to send to, as long as there is a program listening on the port on the client computer, they will pick up the file.

    But since it's UDP, you probaly also have to add a CRC (or something like that) to make sure (on the client side) that you received the entire file.

    Here is a related thread (To see how to broadcast):
    VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)

    I don't have time right now to make an example on how to do this (maybe when I get home)

  38. #38
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: VB - How to send a file using the Winsock control

    If I use these forms in my two different projects (Client Form in one project and Server From in other project) Im getting Type Mismatch error at line FitTextInListView Me.lstConnections, 1, , K + 1 at the tmrStatus_Timer() at the ServerReceive Module
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  39. #39
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: VB - How to send a file using the Winsock control

    Quote Originally Posted by CVMichael
    If you transfer through local network, then there is a much better solution...

    Right now, (if you reverse), when you send a file that is 50 MBytes * 5 times, that will be 250 MBytes sent over the network.
    Yes, Im transferring thru the local network only (LAN)

    I will be sending different set of files from the data process pc to each printing machine...that is for the Machine1, I will send the files for Job No. 1234, Machine2, I wll send the files for Job No. 1235 and so on...

    I dont want to broadcast the files instead choosing some set of files to each machines based on the job number specified. And also I want to pass the information of the directory where it has to be stored.

    Hope Im not confusing...If you want me to explain it more, I will do
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  40. #40

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: VB - How to send a file using the Winsock control

    Hi ganeshmoorthy,

    I understand now... before I assumed you send the same file to all computers...

    As I was saying before, right now I'm at work, and I don't have time, but hopefully I'll remember to make an example for you when I get home. I will probably add the example as a new thread in the CodeBank...

    PS, how do you know what file to send to each computer appon connection ?

Page 1 of 3 123 LastLast

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