Solved

Winsock control TCP/IP data arrival event

Posted on 1999-01-13
4
869 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 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

751 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