|
-
May 8th, 2002, 09:10 PM
#1
Thread Starter
Hyperactive Member
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:
winsock.SendData "START_SEND_FILE"
file_name = CommonDialog1.FileName
SendFile file_name, Wins
first_time = True
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
-
May 8th, 2002, 09:13 PM
#2
PowerPoster
Try adding "DoEvents" like this:
VB Code:
winsock.SendData "START_SEND_FILE"
file_name = CommonDialog1.FileName
SendFile file_name, Wins
first_time = True
DoEvents
winsock.SendData "FINISH_SENDING_FILE"
or you can send the last string when you recieve a "SendComplete"(or something like that) event.
-
May 8th, 2002, 09:17 PM
#3
Thread Starter
Hyperactive Member
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?
-
May 8th, 2002, 09:17 PM
#4
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
-
May 8th, 2002, 09:19 PM
#5
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:
DoEvents: DoEvents: DoEvents
-
May 8th, 2002, 09:21 PM
#6
Thread Starter
Hyperactive Member
the problem is that i need to wait till the SENDFILE function finishes before it sends the second message. will adding doevents ensure this?
-
May 8th, 2002, 09:24 PM
#7
PowerPoster
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.
-
May 8th, 2002, 09:29 PM
#8
Thread Starter
Hyperactive Member
so does that mean it will ensure that my function will finish before sending the second message? if yes then good news to me
-
May 8th, 2002, 09:35 PM
#9
PowerPoster
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.
-
May 8th, 2002, 09:38 PM
#10
Thread Starter
Hyperactive Member
so does that mean it will ensure that my function will finish before sending the second message? if yes then good news to me
-
May 8th, 2002, 09:39 PM
#11
Thread Starter
Hyperactive Member
looks like doevents don't help...
-
May 8th, 2002, 09:43 PM
#12
You can check it like this:
VB Code:
Text1.Text = "Testing..."
DoEvents
MsgBox "First Delay"
Text1.Text = "Testing Delay"
DoEvents
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
-
May 8th, 2002, 09:45 PM
#13
Thread Starter
Hyperactive Member
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?
-
May 8th, 2002, 09:48 PM
#14
PowerPoster
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:
Dim sendingstuff As String
Private Sub mysub()
file_name = CommonDialog1.FileName
SendFile file_name, Wins
sendingstuff = "SendingAFile" 'tell what you have just sent
first_time = True
End Sub
Private Sub Winsock1_SendComplete()
'if we were sending the above file then now it's done sending
If sendingstuff = "SendingAFile" Then
Winsock.SendData "FINISH_SENDING_FILE"
End If
End Sub
-
May 8th, 2002, 09:49 PM
#15
PowerPoster
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.
-
May 8th, 2002, 09:54 PM
#16
Thread Starter
Hyperactive Member
winsock1_sendcompelte will only fire once everything is sent out?
-
May 8th, 2002, 09:56 PM
#17
PowerPoster
Yes, it'll only be fired when whatever you send with ".SendData" is completely sent to the remote computer.
-
May 8th, 2002, 09:59 PM
#18
Thread Starter
Hyperactive Member
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
-
May 8th, 2002, 10:06 PM
#19
PowerPoster
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.
-
May 8th, 2002, 10:21 PM
#20
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|