Results 1 to 20 of 20

Thread: winsock

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321

    winsock

    dear pple

    i'm facing a problem using winsock

    in my program i have two winsock control. one to send and receieve data and the other to send and receieve messages. these messages act to start or stop some controls on the other app.

    the problem is this. i entered code like this
    VB Code:
    1. winsock.SendData "START_SEND_FILE"
    2.         file_name = CommonDialog1.FileName
    3.         SendFile file_name, Wins
    4.         first_time = True
    5.         winsock.SendData "FINISH_SENDING_FILE"

    the problem is at the receiving side, i get both message appended to each other at the same time. since the sendfile function is long, isn't it supposed to finish running the sendfile funtion before sending the second message?

    please help

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Try adding "DoEvents" like this:
    VB Code:
    1. winsock.SendData "START_SEND_FILE"
    2.         file_name = CommonDialog1.FileName
    3.         SendFile file_name, Wins
    4.         first_time = True
    5.         DoEvents
    6.         winsock.SendData "FINISH_SENDING_FILE"

    or you can send the last string when you recieve a "SendComplete"(or something like that) event.
    Baaaaaaaaah

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    thanks!

    it works..

    what's the use of a doevents here???
    how does it help in seperating both messages?

    does this mean that everytime i need to senddata more than once i need to insert doevents in between?

  4. #4
    Stiletto
    Guest
    You can use DoEvents, which will make a lil delay between the codes, or you can make the reciver side to msg-back the sender that he got the file and send the last string

  5. #5
    Stiletto
    Guest
    Originally posted by ongtw
    thanks!

    it works..

    what's the use of a doevents here???
    how does it help in seperating both messages?

    does this mean that everytime i need to senddata more than once i need to insert doevents in between?
    DoEvents will couse a delay between the two codes, it will run the first code, wait a lil and then will run the second code.
    If you want to increase the delay, you can use
    VB Code:
    1. DoEvents: DoEvents: DoEvents

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    the problem is that i need to wait till the SENDFILE function finishes before it sends the second message. will adding doevents ensure this?

  7. #7
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I actually have no clue why DoEvent works for nothing sending all the strings at the same time but it just works. As I know, main purpose of DoEvents is to let Window do other stuff while it's performing the code before DoEvents.
    Baaaaaaaaah

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    so does that mean it will ensure that my function will finish before sending the second message? if yes then good news to me

  9. #9
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I hope so but it depends on the internal structure of the TCP/IP stack and how winsock is internally configured. I think it will put all the data on the TCP/IP stack first and it'll send it either as a stream or message by message.
    Baaaaaaaaah

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    so does that mean it will ensure that my function will finish before sending the second message? if yes then good news to me

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    looks like doevents don't help...

  12. #12
    Stiletto
    Guest
    You can check it like this:
    VB Code:
    1. Text1.Text = "Testing..."
    2. DoEvents
    3. MsgBox "First Delay"
    4. Text1.Text = "Testing Delay"
    5. DoEvents
    6. MsgBox "Second Delay"
    Run this, if you got the MsgBox popup, and you see Text1.Text with the string, that means that DoEvents will wait until the process is done, and then will continue to the second code

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    it only delays the program.

    the thing i need is to wait until the sendfile finishes before it sends out the message

    one more thing.. if i added a function in a module, when that funtion is called, does the calling form wait until the function finishes before moving on?

  14. #14
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by ongtw
    looks like doevents don't help...
    Have you tested it? I hoped it would work but if it doesn't you can just do something like:
    VB Code:
    1. Dim sendingstuff As String
    2. Private Sub mysub()
    3.         file_name = CommonDialog1.FileName
    4.         SendFile file_name, Wins
    5.         sendingstuff = "SendingAFile" 'tell what you have just sent
    6.         first_time = True
    7. End Sub
    8.  
    9. Private Sub Winsock1_SendComplete()
    10. 'if we were sending the above file then now it's done sending
    11. If sendingstuff = "SendingAFile" Then
    12.         Winsock.SendData "FINISH_SENDING_FILE"
    13. End If
    14. End Sub
    Baaaaaaaaah

  15. #15
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by ongtw
    it only delays the program.

    the thing i need is to wait until the sendfile finishes before it sends out the message

    one more thing.. if i added a function in a module, when that funtion is called, does the calling form wait until the function finishes before moving on?
    Yes, but you can make it execute more than one functions, subs, or whatever by putting them in their own threads. You will have to do multithreading for that which vb doesn't completely support.
    Baaaaaaaaah

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    winsock1_sendcompelte will only fire once everything is sent out?

  17. #17
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Yes, it'll only be fired when whatever you send with ".SendData" is completely sent to the remote computer.
    Baaaaaaaaah

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    i have another quetion.

    if this is the case, since i'm breaking the file up into chunks, so i will need to senddata quite a lot of times if the file is big. so by adding the function i think it will not work right?

    cos the winsock1_sendcompelte() will fire everytime senddata finish executing. and in my position, i want it to fire only after i finish sending all packets

  19. #19
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Yes, it will be fired after every chunk of file is sent. You can just have another variable that specifies how much size of data is sent. You increase the value by a certain size of your file's chunk and then you only send your second command when the total size of the data already sent is same as your total file size.
    Baaaaaaaaah

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    thanks... i did soemthing like that and it works perfectly fine..

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