Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Winsock control TCP/IP data arrival event

Posted on 1999-01-13
4
Medium Priority
?
972 Views
Last Modified: 2013-12-25
A current project has required me (old MF BAL programmer, but Visual Basic beginner) to connect a Windows NT PC applcation to an IBM mainframe CICS application using TCP/IP.  I have successfully accomplished this via Visual Basic using the Winsock control on the PC.  However, one surprise was that in the executable version of the code  (not in the development mode), when data arrived from the MF, and I popped a Msgbox in the data arrival event, the box would display, but if more MF data arrived, Windows would again  fire  the data arrival event  resulting in two or more events processing through the same data arrival event code simultaneously.  My question is, using the Winsock control, when is the data arrival event triggered by Windows, and is there anyway to tell Windows to wait until the current data being processed is completed  (End of data arrival sub) before firing a new data arrival event?  Thanks!  
0
Comment
Question by:aurelia
  • 2
4 Comments
 
LVL 3

Expert Comment

by:cognition
ID: 1489674
You will need to code a queue, or to process the data as soon as it arrives.

I have done this using a list box. All new data is added to the end of the listbox, and a timer takes the first item in the list box, and processes it. More data arriving is added to the listbox as it arrives.

Having message boxes, or modal forms appear can cause problems if they prevent processing of the arriving data.

The only way round, is to set up some sort of protocol, to ask for more data, and to ask to stop sending.

0
 

Author Comment

by:aurelia
ID: 1489675
Thanks, for confirming my MsgBox problem and your great solution to get around the problem.  I would like to accept your answer as excellant, but would still like the following answered.

Using the Winsock control, WHEN is the data arrival event triggered by Windows, and IS THERE anyway to tell Windows to wait until the current data being processed is completed  (End of data arrival sub) before firing a new data arrival event? 
0
 

Accepted Solution

by:
kianwei earned 400 total points
ID: 1489676
There is one of the  way u can ensure the data process completely (end of the data arriaval sub), ie. group your process into a sub or function, and then create a thread for it.
of course, u also have to cater for the synchronization between them, u can
do this as well by using the mutex synchronization.

for example,
   
u can group your process into one function, let say, fnMessageHandler

then in the data arrival event, u can call the createThread API to
spawn a thread for your fnMessageHandler,

      Private Const CREATE_SUSPENDED = &H4 ' declare in modules
      private const INFINITE = &HFFFF

      Dim dwStackSize as long
      Dim lpThreadId as long
    dwStackSize =0
    ThreadHandler = CreateThread(0&, dwStackSize, AddressOf fnMessageHandler, 0&, CREATE_SUSPENDED, lpThreadId)
      ' u should store the thread handler into a dynamic array since u don't
        know how many thread u r going to create or u can create the Thread class.

now u have to take care of the synchronization between thread, u can do that
by using the createMutex API form load event.

      lHandleMutex = CreateMutex(0, True, "TestMutex")

in your fnMessageHandler function

      private sub fnMessageHandler()
            l = WaitForSingleObject(lHandleMutex, INFINITE)
            your process here...
          l = ReleaseMutex(lHandleMutex)
          DoEvents
      end sub
 



0
 

Expert Comment

by:kianwei
ID: 1489677
i am not sure this method that i mentioned above really u or not..
hopefully it's really help u, thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question