Solved

Winsock control TCP/IP data arrival event

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

828 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