Solved

Winsock control TCP/IP data arrival event

Posted on 1999-01-13
4
825 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 100 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now