PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VB - How to send a file using the Winsock control-VBForums
Page 1 of 2 12 LastLast
Results 1 to 40 of 86

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

Hybrid View

  1. #1

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

    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,785

    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,785

    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
    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.

  7. #7
    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:

  8. #8

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

    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  

  9. #9

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

    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

  10. #10
    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.

  11. #11

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

    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....

  12. #12
    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.


  13. #13
    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

  14. #14

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

    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

  15. #15
    New Member
    Join Date
    Feb 2012
    Posts
    3

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

    If many person send a similar file we see Error word in the program .
    How can correct this action?
    Thanks.

  16. #16
    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.

  17. #17

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

    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...

  18. #18
    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?

  19. #19

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

    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

  20. #20
    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??”

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

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

    filing-cabinets = Files

  22. #22
    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??"

  23. #23

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

    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.

  24. #24
    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????

  25. #25

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

    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 !

  26. #26
    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

  27. #27

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

    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...

  28. #28
    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.


  29. #29

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

    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)

  30. #30
    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.


  31. #31
    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.


  32. #32

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

    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 ?

  33. #33

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

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

    I started making the sample application, but it's gonna take a few days because it's a little complicated and I don't have a lot of time per day to do this. It's gonna be multithreaded & using API for file read/write (therefore files greater than 2GB).

    But I need you to answer to my question so I know how to make the sample: How do you know what file to send to each client when it connects ?

    Is the client requesting for a file ?
    Or you just send file "X" when the IP matches with a list you already set in the server ?
    Or some other criteria ?
    Last edited by CVMichael; Sep 25th, 2007 at 07:35 AM.

  34. #34
    New Member
    Join Date
    Jul 2009
    Posts
    2

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

    Hi,

    In continuation to sending file thru Winsock I have a question.

    I have a Server receiving data from a ADConverter[with TCP/IP Interface] thru winsock W1.

    Now I have 2 other Displays and 6 PCs where the data received is to be displayed. The DIsplay Units are having TCP/IP interface.

    In my server program I have incorporated two other winsock W2, W3.

    Indivisually when I am sending data to W2 or W3 by senddata each of them are displaying data on dataarrival from W1.

    Problem is if I connect W3 after W2, the display on Display-W2 stops but Display-W3 working and vice versa.

    Any solution.... URGENTLY NEEDED.

    Thax & Regards.
    SG

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

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

    Hi ganeshmoorthy,

    i have manage to play arround with this code, and come up with something like you want, coz i had the same problem before.

    By adding receiving functionality to the client (from the server) and sending functionality to the server(from client), can send and receive files. Note you can receive files from the server as long the file is in the server's folder.

    i went further, by modifying this code to fit my requirements, now i can send and receive multiple files. in the attached modified version file there is server and part of client code which can send and receive multiple files.
    Attached Files Attached Files

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

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

    CVMichael

    I'm trying to develop a client -server application,
    where by users (on client side) need to attach(upload) and view(download) files from server machine.

    which is best way to use to store my files between
    1) using database to store files or
    2) writing server application to receive and send files to the clients, like the one u provided.
    Last edited by ppitta; Sep 25th, 2007 at 12:52 AM.

  37. #37
    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

    Thank you very much for your interest in making a sample for me !!!
    Quote Originally Posted by CVMichael
    But I need you to answer to my question so I know how to make the sample: How do you know what file to send to each client when it connects ?
    The user will select multiple files from a flexgrid and click on the send button.
    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.


  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

    ppita,
    thank you very much for your work...let me check the code and get back to you..
    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

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

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

    Quote Originally Posted by ganeshmoorthy
    The user will select multiple files from a flexgrid and click on the send button.
    So, where is the flexgrid ? on the server or on the client ?

    In other words, the user on the server decides what to send to client ? Or the client decides what he/she wants to receive from the server ?

    PS. I need a few more days to finish it, until now I had bad luck (yesterday there was no power in the whole building, so I could not even start the computer)

  40. #40
    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
    In other words, the user on the server decides what to send to client ? Or the client decides what he/she wants to receive from the server ?
    The user on the server decides what to send to client...
    Quote Originally Posted by CVMichael
    PS. I need a few more days to finish it, until now I had bad luck (yesterday there was no power in the whole building, so I could not even start the computer)
    My bad....
    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.


Page 1 of 2 12 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
  •  



Featured


Click Here to Expand Forum to Full Width