How to handle threading for TCP communicat​ion?

Hi,
I've a project to control two separate applications (C++ and LabView) and both of them are implemented as server. Another client program (C++) is used to control those application. The communication among them are implemented using TCP socket. The client program sends message to start or stop some tasks on the servers. The client program also sends time (hh:mm:ss) with the start and stop message to determine when to start or stop.
In C++ application (server): The application listens for connection and when gets  one, it creates a communication thread to handle that and again listen for another connection. The communication thread handles message passing and when it receives start or stop message, it creates a timer thread with the received time to trigger a task at specified time. And after that it waits for message from the client. So, here, when thread (communication, timer) is needed, it is created.
In LabView (server): I've tried to create same thing as the C++ server. But, from LabView manual and others forum threads, I got that LabView is multithreading and it can be done using independent loop. So, I'd to create four loops in a diagram:
1. Listen for new connection
2. Handle communication for already received connection
3. Start timer
4. Stop timer
and they are run at the beginning of the execution and communication among them are managed using local variables. But, 2,3 and 4th loop can handle only one connection and it can handle another if the current is closed. But, the C++ application can handle more than one connection by creating thread when it is necessary but not at the beginning of the execution of the application.
Is there a better way to implement this in LabView?
Is it possible to handle multiple connections and create diagram node/block (like thread) dynamically like C++?
Thanks.
Using LabVIEW 2010, Visual C#, Visual C++ (2005, 2008, 2010)
Solved!
Go to Solution.

There are several ways to do this in modern LabVIEW and you should probably search the Example Finder for some TCP examples. The classic way is to transfer the connection refnum from the listen loop to a communication loop that adds it to an array of connection IDs and then continously iterates over this array to do the communication. It works since about LabVIEW 4.0 perfectly for me even for applications with HTTP based communication protocol. But you need to make sure of course that the communciation handling for one connection isn't delaying its work for some reasons as that would delay the handling of the other connections too, as they are really worked on sequentially. If you encounter an error, the connection ID is closed and removed from the array.
The other is that you create a VI that does your whole communication and terminates itself on an error or when getting the quit command. Make this VI to be reentrant and then launch it through VI server as reentrant instance, passing it the newly received connection refnum form the listen loop. Then use the Run method to let it start and operate like an independant thread.
For all of these you should be able to find an example in the Example Finder when searching for TCP.
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions

Similar Messages

  • How to handle bdc for more than one transaction?

    how to handle bdc for more than one transaction?

    Hi srk,
    I am providing you with some references below. Hope this prove to be helpful to you.
    Method 1:
    Use one BDC_OPEN_GROUP
    Multiple BDC_INSERT 
    One BDC_CLOSE_GROUP.
    Call function BDC_OPENGROUP.
    Build BDC data and call lBDC_INSERT for transaction 1
    Build BDC data and call lBDC_INSERT for transaction 2
    Build BDC data and call lBDC_INSERT for transaction 3
    paas the tcodes to bdc_insert.
    call function BDC_CLOSE_GROUP.
    Also check this out:
    Here we need to record 2 transactions (shdb).
    Once completion of the recording. Populate the data into input internal table .
    Loop the internal table and process the 2 transactions
    like
    1. BDC_OPEN_GROUP
    2. LOOP AT ITAB
    a. Populate first transaction recording data
    and pass transaction to the BDC_INSERT_GROUP.
    BDC_INSERT_GROUP.
    b. Populate second transaction recording data
    and pass transaction to the BDC_INSERT_GROUP.
    BDC_INSERT_GROUP.
    ENDLOOP.
    3. BDC_CLOSE_GROUP
    the above info can be found at : How to use 2 transactions in BDC?
    Also check this out:
    Suppose u have created recordings for transactions 'MM01' 'XK01' and 'VA01'.
    Then do this:
    bdc_open_group.
    after this we have to fill the bdcdata structure for one transaction.here 'MM01'.
    bdc_insert.
    refresh bdcdata.
    after this we have to fill the bdcdata structure for one transaction.here 'xk01'.
    bdc_insert .
    refresh bdcdata.
    after this we have to fill the bdcdata structure for one transaction.here 'va01'.
    bdc_insert.
    bdc_close_group.
    Hope these are useful to you.
    Please reward if any of the above are useful.
    Regards,
    Kalyan

  • How to handle thread

    i am using two methods. one is send method to send message and another one is receive method to receive message.if i am typeing message that time i want check if any message is receive or not.If any receive i want to display that receive.

    Double-post: http://forum.java.sun.com/thread.jspa?threadID=761176
    You really don't seem to know how to handle threads...

  • How to handle Thread synchronization

    Hi guys,
    already i have posted the question for this problem.
    but there i didn't explain properly.
    so, just bare with my explanation and give me solution.
    i am doing with Swings,
    I have,
    Master class ( having main())
    |
    |
    |
    V
    Sub Class-------> calling a thread class
    here the child class will throw a msgbox after its completion of execution to the sub-class interface.
    the code in the sub-class should continue only after the complete execution of the child thread, i.e after it got the msgbox thrown by child thread.
    say, on the 100th line of sub-class file we are calling the child thread, then the 101st line should not get executed before the child thread has executed completely.
    in my case it is getting executed.
    how to handle the situation.
    thanx in advance.
    --subbu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi, thank you for your reply.
    I am NOT creating a JVM in my C/C++ application.
    The problem is when I call __declspec( thread ), the system crash.
    Your suggestion is if I call from java to C++, for example, send data to C++, I do NOT need handle the thread whatever the C++ use thread and Socket.
    You are right. The C++ code works well in VC++ environment. And the JNI code works well to call simple C++ code (testing).
    I handle exception in Java side. That means I use try .. catch.. block to handle native method. But you mean I need check error and exception in C++ side ?
    For example
    jint err = env->MonitorEnter(obj);
    if (err)
         //todo
    else
    // todo
    I will handle it in the real code.
    I appreciate your suggestion.
    Have a good day
    anne

  • How to handle error for a file to file transform in ODI

    I am doing a lab for file to file transformation where source = CSV file and target = Flat file.
    1) When I am changing the datatype in source two files are getting created where one having the errored out data and the other having the errored message, how how to handle the errored data?
    2) If the target path is changed the session in ODI is showing as completed, it should error out. Here no files are created in source as earlier. Hoe to handle this type of error?

    Hi,
    I have used the following KMs in my transformation with the following options:
    IKM SQL Incremental Update
    INSERT    <Default>:true
    UPDATE    <Default>:true
    COMMIT    <Default>:true
    SYNC_JRN_DELETE    <Default>:true
    FLOW_CONTROL    <Default>:true
    RECYCLE_ERRORS    <Default>:false
    STATIC_CONTROL    <Default>:false
    TRUNCATE    <Default>:false
    DELETE_ALL    <Default>:false
    CREATE_TARG_TABLE    <Default>:false
    DELETE_TEMPORARY_OBJECTS     <Default>:true
    LKM SQL to SQL
    DELETE_TEMPORARY_OBJECTS    <Default>:true
    CKM Oracle
    DROP_ERROR_TABLE    <Default>:false
    DROP_CHECK_TABLE    <Default>:false
    CREATE_ERROR_INDEX    <Default>:true
    COMPATIBLE    <Default>:9
    VALIDATE    <Default>:false
    ENABLE_EDITION_SUPPORT    <Default>:false
    UPGRADE_ERROR_TABLE    true

  • How to handle error for a Db Table to Db table transform in ODI

    Hi,
    I have created two table in two different schema source and target, where there is a field for e.g.- place where the datatype is varchar2 and data inserted is string.
    In designer model of ODI i have put the type of place as number in both source and target and accordingly done the mapping.
    When it is executed it should give an error, but it got completed but no data is inserted neither in target table nor in error table in the target schema(E$_TARGET_TEST which is created automatically).
    Why the error is not given and how to handle such type of error..
    Please help.
    The codes for source and target tables are as follows:
    source table code:
    CREATE TABLE "DEF"."SOURCE_TEST"
        "EMP_ID"   NUMBER(9,0),
        "EMP_NAME" VARCHAR2(20 BYTE),
        "SAL"      NUMBER(9,0),
        "PLACE"    VARCHAR2(10 BYTE),
        PRIMARY KEY ("EMP_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ENABLE
    inserted data:
    INSERT INTO "DEF"."SOURCE_TEST" (EMP_ID, EMP_NAME, SAL, PLACE) VALUES ('1', 'ani', '12000', 'kol')
    INSERT INTO "DEF"."SOURCE_TEST" (EMP_ID, EMP_NAME, SAL, PLACE) VALUES ('2', 'priya', '15000', 'jad')
    target table code:
    CREATE TABLE "ABC"."TARGET_TEST"
        "EMP_ID"     NUMBER(9,0),
        "EMP_NAME"   VARCHAR2(20 BYTE),
        "YEARLY_SAL" NUMBER(9,0),
        "BONUS"      NUMBER(9,0),
        "PLACE"      VARCHAR2(10 BYTE),
        PRIMARY KEY ("EMP_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ENABLE

    Hi,
    I have used the following KMs in my transformation with the following options:
    IKM SQL Incremental Update
    INSERT    <Default>:true
    UPDATE    <Default>:true
    COMMIT    <Default>:true
    SYNC_JRN_DELETE    <Default>:true
    FLOW_CONTROL    <Default>:true
    RECYCLE_ERRORS    <Default>:false
    STATIC_CONTROL    <Default>:false
    TRUNCATE    <Default>:false
    DELETE_ALL    <Default>:false
    CREATE_TARG_TABLE    <Default>:false
    DELETE_TEMPORARY_OBJECTS     <Default>:true
    LKM SQL to SQL
    DELETE_TEMPORARY_OBJECTS    <Default>:true
    CKM Oracle
    DROP_ERROR_TABLE    <Default>:false
    DROP_CHECK_TABLE    <Default>:false
    CREATE_ERROR_INDEX    <Default>:true
    COMPATIBLE    <Default>:9
    VALIDATE    <Default>:false
    ENABLE_EDITION_SUPPORT    <Default>:false
    UPGRADE_ERROR_TABLE    true

  • Using blackberry as modem for wireless communicat​ion for laptop

    I've seen this done but wasn't able to find instructions on how to do this. Does anyone know how to use the blackberry curve as a modem for wireless connectivity for laptop?  What settings do I need and any software for the laptop needed?

    Hi there!
    Here are the RIM KB's about the topic. All other information you will need to get from your carrier.
    KB05178 Support for tethered modem use
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • TCP communicat​ion temporaril​y dies

    Hi There
    Im using TCP to communicate between my ARM processor and PC. However, the communication sporadically dies for 3 to 4 seconds and then resumes, as shown in the Task Manager Networking (attachment 1) . This happens with the simplest of test programs, as shown in the attachments, and no delays or sequences seemed to solve the issue. 
    After some duration the communication dies completely with error code 66.
    What is causing the delays in communication and is there a fix for this?
    Attachments:
    simple TCP failure.jpg ‏527 KB
    Simple Server - ARM.jpg ‏72 KB
    Simple Client - PC.jpg ‏74 KB

    Hey,
    What kind of delay did you add into the VI?  it sounds like a pretty classic case of reading and writing TCP too fast.  You may want to take a look at this article: http://digital.ni.com/public.nsf/allkb/4CB799F36D0​EA56A862576200064B2F9?OpenDocument
    Regards,
    Eric L.
    Applications Engineer
    National Instruments

  • How to handle DLSw for SDLC and token-ring to same remote peer

    We have the need to have SDLC and token-ring connections from one local router to a the same remote site. Currently we have a remote peer for token-ring:
    dlsw port-list 10 TokenRing0/0
    dlsw remote-peer 10 tcp a.b.c.d lf 1500
    We have an SDLC link on a serial port. I understand that SDLC is part of group 0. How do I also get the SDLC traffic to the same remote peer? Is it as simple as adding another remote peer statement to the same IP?
    dlsw remote-peer 0 tcp a.b.c.d lf 1500

    Do you have your token ring configuration complete to bridge to DLSW ?
    for example;
    source-bridge ring-group 2000
    dlsw local-peer peer-id 150.150.10.1
    dlsw remote-peer 0 tcp 150.150.10.2
    interface loopback 0
    ip address 150.150.10.1 255.255.255.0
    interface serial 0
    ip address 150.150.11.1 255.255.255.192
    interface serial 1
    description PU2 with SDLC station role set to secondary
    no ip address
    encapsulation sdlc
    no keepalive
    clockrate 9600
    sdlc role primary
    sdlc vmac 4000.9999.0100
    sdlc address 01
    sdlc xid 01 05d20006
    sdlc partner 4000.1020.1000 01
    sdlc dlsw 1
    interface serial 2
    description Node Type 2.1 with SDLC station role set to negotiable or primary
    encapsulation sdlc
    sdlc role prim-xid-poll
    sdlc vmac 1234.3174.0000
    sdlc address d2
    sdlc partner 1000.5aed.1f53 d2
    sdlc dlsw d2
    interface tokenring 0
    no ip address
    ring-speed 16
    source-bridge 100 1 2000
    source-bridge spanning
    If your SDLC link is working through DLSW (it is in DLSW ring group 10 according to your first configuration statement and port list statement and must match at both ends), it should be an easy modification to add the token ring configuration to join the bridge to the remote DLSW router.
    See;
    http://www.cisco.com/univercd/cc/td/doc/product/software/ios122/122cgcr/fibm_c/bcfpart2/bcfdlsw.htm#1003756
    best of luck

  • How to Handle Events for JOptionPane buttons?

    Hi All,
    I need a help...
    I am trying to develop a simple SWING application that consists of multiple elements (mainly text fields) and a Submit button. On pressing Submit button, it should validate all the fields and then do something else. But if some fields are left blank, then it should give a pop-up message and on clicking the OK button on the pop-up message, the focus should go to that text field which is left null.
    The problem is I am not able to understand how to Capture this OK button click-event of the pop-up message. I mean how to do something when the OK/Cancle button of the pop-up window is clicked.
    Please Help me.
    Thanks in Advance,
    Ujjal

    As already pointed out, JOptionPane has some static methods which show a dialog, and return an int, or a string. The whole point of this class is to remove the need for any event handling by the developer, that is, you simply call the showDialog method or whatever, and it returns a value telling you, for example, which button was pressed - no need for action listeners at all. The result of the showDialog method (or whichever you use) tells you which button was pressed. Check the javadocs for JOptionPane for details of several constants that indicate which button was pressed
    The class exists to make simple dialogs trivial to generate - you're overcomplicating things!

  • How to handle TDS for Contractor under Section 94C in SAP B1 9.0

    Hi Expert
    If the credit or the payment (One time Payment) in pursuance of the contract does not exceed Rs.30,000/-, no deduction has to be made at source. However , if the aggregate of all amounts paid/credited or likely to be paid/credited exceeds Rs. 75,000/- then tax at source is to be deducted.
    how to manage this in SAP B1 with single WTax code??
    regards,
    Raviraj

    HI Raviraj,
    Have you checked the same by setting the threshold as 75000? You may not be able to deduct TDS at the the time of payment but you can use DP Invoice for the same.
    Try this, it should work.
    Thanks,
    Joseph

  • LabWindows​/CVI 5.5 for GPIB communicat​ion?

    Hello!
    I'm a GPIB rookie and can't get my GPIB devices to talk with LabWindos/CVI:
    For the GPIB devices I am using (FWBell 7030 Gaussmeter, Keithley 6514 Electrometer) are no instrument modules available (at least I can't find any).
    How can I talk with these devices, using the IEEE488(.2) functions in LabWindows 5.5?
    If I use these functions (i.e. Send / Receive), I allway get error messages and the devices don't redspond and sometimes they show error messages.
    How do I address a device on the GPIB Bus?
    Every idea is welcome, I need all the help I can get.
    Thank you!"

    Unfortunately I was unable to find a driver for this instrument either. This leaves you with one of a couple options. First, I would like you to submit a request for this driver at:
    http://zone.ni.com/idnet/other.htm
    We develop drivers based on demand and popularity so the more requests we have for it, the greater the possibility that we will develop one.
    If you would like to try developing your own instrument driver (or modify the existing one), we have documentation, model instrument drivers, and driver templates to help at :
    http://zone.ni.com/idnet/development.htm
    There may be a similar driver on ni.com/idnet that can be used as a model.
    We also have a syndicate of third party vendors that specialize in National Instruments'
    products and services. Some of the vendors specialize in driver development. I would suggest contacting one of the Alliance members at:
    http://www.ni.com/alliance

  • TCP COMMUNICAT​ION ON INTERNET

    Hello..
           There is one example "TCP communication client-server model" in example finder.  I have tested it. It is running on local LAN connection. 
    What should I do to run it on internet...
    Please let me know
    Thanks
    Prashh 

    The only thing you need to change to run that example across the world, rather than across the room, is the IP addresses.
    Your machines have to have internet access to the outside world, of course.
    I have a couple of blog entries describing the basics of TCP communications: 
    http://culverson.com/category/tcp/ 
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • How to handle pricing for items sold in prepacks

    The requirement:  Sell individual items together as a prepack and offer a discounted price.  These individual items in the preapck are also sold individually at full price.
    The Issue: Returns.  If a customer returns the individual item, how do we know if it was sold as the prepack or individuallyu2026so we end up crediting the customer the higher value.
    Your suggestions will be appreciated.
    Regards,
    Hemanth

    Hi,
    you have to use authorizations in this case for approval process in CATS IT 0316 and It 0328 are used for authorizations. These are two dummy infotypes.
    it is verymuch possible to enter data in CATS for a single PERNER via two or more profiles.
    Regards,
    Kapil Kaushal

  • TCP communicat​ions via C program with VI on a PC (SGI - Windows)

    I have a pair of simple (more at prototype) client/server C programs on an
    SGI host. On the SGI, they compile and run fine (using separate windows).
    I know what the server is supposed to be sending (C floats) and the client
    is reading the correct values.
    I now want to start my C program server on the SGI host, and use the Simple
    Data Client.vi (in LabVIEW 6.1's examples) to display (in its graph) the
    floating point values that the SGI host is sending.
    So far, I have not had complete success. If I start my SGI server, and
    "point" the example Simple Data Client VI at my server, the LabVIEW client
    gets immediate errors (overflows).
    As an experiment, I tried going the other way. That it, I started up
    the
    Simple Data Server VI on the Windows PC. I then "pointed" my SGI client at
    the server on the PC. It works, ... sort of. I am getting an
    appropriately sized list of numbers displayed on the SGI host, but while
    most look like floating point values, some look like VERY large integers.
    I believe I have a data representation problem. That is, I don't know if I
    should expect to send (server-side) or see (client-side) C programming
    variables of type 4-byte floats, 8 byte doubles, or something else. Also, I
    am not certain how many values I should expect to send/see in each message.
    I think the default for the Simple Data Client/Server programs is 200
    points, but I am not sure what that really means, either.
    Any suggestions would be very much appreciated.
    Mike McCormick
    Michael J. McCormick
    Phone: 520-545-7972
    Fax: 520-794-9400
    Email: [email protected]

    > As an experiment, I tried going the other way. That it, I started up the
    > Simple Data Server VI on the Windows PC. I then "pointed" my SGI client at
    > the server on the PC. It works, ... sort of. I am getting an
    > appropriately sized list of numbers displayed on the SGI host, but while
    > most look like floating point values, some look like VERY large integers.
    >
    > I believe I have a data representation problem. That is, I don't know if I
    > should expect to send (server-side) or see (client-side) C programming
    > variables of type 4-byte floats, 8 byte doubles, or something else. Also, I
    > am not certain how many values I should expect to send/see in each message.
    > I think the default for the Simple Data Client/Server programs is 200
    > points
    , but I am not sure what that really means, either.
    >
    By default, LV converts all of the datatypes to be in big endian form.
    I'm not sure about your SGI, but if it is a little endian machine, then
    that will cause problems. If that is the case, you will want to swap
    the words and bytes of the four byte values.
    To debug this more easily, you might just make sure you send over very
    predictable data such as 0, 1, 2, 3, etc. Lots of times these are
    tested with random data, but that makes it pretty hard to see a pattern
    when the data is wrong.
    Greg McKaskle

Maybe you are looking for