Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Winsock control TCP/IP data arrival event

Posted on 1999-01-13
4
Medium Priority
?
929 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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