Click to See Complete Forum and Search --> : Winsock - how to capture the RECEIVE event
mskvarenina
March 2nd, 2000, 11:46 AM
I am writing a C/S app that communicates over TCP/IP to a mainframe. This app will have many forms. In the past my approach has been to put the winsock control on my main form and have whatever form that needed to send some data simply reference the main form. The recieve was much harder though since the recieve fires whenever something is received. What I did in my previous apps was simply do the send, switch to an hourglass, and wait till the recieve fired. When it did, it would receive the data and I kept track of what function it was going prior to the send so it knew to unlock the screen and resume processing.
What I would like to acheive however is some was to simply allow the recieve to run in the background and accumulate the data in a buffer or string until I want to extract some data from it. This way I could for example, send some data, wait a few seconds, then enter a loop to receive the data from the buffer or string WITHIN THE SAME PROCEDURE and continue processing. What happens how is the recieve event fires and my program jumps to the receive event and doesn't return to where it left off obviously.
So has anyone had experience with this situation and if how how did you resolve it? I am thinking maybe there is a way to put the control into a .bas module or maybe buying a control that has this functionality.
mskvarenina
March 2nd, 2000, 12:21 PM
Actually what I am asking is is it possible to convert the receive event into a method instead so I can call it rather than it firing at will?
March 2nd, 2000, 09:36 PM
Hmmmm, I don't think it's possible to bypass the DataArrival event with the default winsock control - unless you just don't put any code in that event's code area. It will still be called when the winsock control recv's data but, obviously, it wouldn't do anything.
Write your own recv function and call that whenever you want to manually recv some data.
Did I understand your question correctly and does that help???
mskvarenina
March 3rd, 2000, 07:38 AM
Yes, you understood correctly but I wouldn't know how to write my own RECV function and have it be able to receive the data off the winsock buffer. It doesn't seem like it's possible to do using the native VB winsock OCX.
So far I found one 3rd party OCX called PowerTCP by Dart which appears to have a receive method as opposed to an event. This is the key, the recv function must be a method in order to accomplish my goal. If you or anyone else knows how to make the native winsock recv event into a method or knows any other 3rd party solution, I'd be interested in hearing about it.
March 3rd, 2000, 08:35 AM
Ok, what about this: Put code in the DataArrival event that caches the incoming data. Then when you want to use that recv'd data, pull it out of the cache variable.
Ravi Kiran
March 4th, 2000, 02:16 AM
ideally you should be running this kind of a thing on a seperate thread.. so vb way of doing this is writing a Active-x Exe.
Write a Activex exe which will be doing this send & recieve part, you can query up this server object for data when ever recquired.
This object could available as a global for all the forms and could be instanciated in the main form (which is now having the winsock control. btw, winsock control would move to the server now)
Also your saying of "doesn't return to where it left off" is not all that correct!, because you can make it go to where it leftoff with Doevents.
function SomeProcedure()
... some steps
Do
DoEvents
if timer() > Sttime + TimeOut then
btimedout = True
end if
loop while m_bstop = false or pMainForm.GotNewData() = False
if m_bstop then
' we aborted because user clicked "Stop" button (assume one exists on the form!)
endif
if btimedout then
' do what ever is required when timed out
' like may be ask to enter another look-up loop or something
end if
if pMainForm.GotNewData() then
' read the info from where ever and process
end if
end function
At the DoEvents line, when the data comes it may go over to that recieve event handler, but it will come back to ptocedure after that.
and GotNewData is a method/property of the main form which will be true after he gets new data .. it is just a rough idea, you get the point, right?
RK
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.