Jump to content

How to register for event for socket or TCP/IP receive data?


Recommended Posts

Hi,

I would like to know how to register for the event of receive data from data socket or TCP/IP. I have used normal read only. Currently I am working on a server which require both TCP/IP and socket and some other dll. I think I should use event in this case.

Please tell me how to do it. I haven't found any example yet.

Best regards,

Thang Nguyen

Link to comment

Hi,

I would like to know how to register for the event of receive data from data socket or TCP/IP. I have used normal read only. Currently I am working on a server which require both TCP/IP and socket and some other dll. I think I should use event in this case.

Please tell me how to do it. I haven't found any example yet.

Best regards,

Thang Nguyen

I am not aware of a way to do this in LabVIEW. What I would recommend that you do is to create a parallel task that will perform your TCP reads. This task will ignore timeouts since it is only interested in reading the raw data. When data is read it would pass that to another parallel task for processing. It could use a queue to pass the data and this would make your processing task event driven. This should give you the overall functionality that you are looking for.

Link to comment

That is exactly how I do it. I am able to read 100's of channels of data over TCP using 100's of VIs spawned from a reentrant VI that uses this process. It is basically a producer consumer architecture where the producer reads the TCP stream and queues up data while the consumer processes this data and decides when to quit.

Link to comment

Thank Mark,

I guess I should do this for all of the channels connect to the server.

I just want to confirm that if this is a really good architecture for a server because this is a CAN server workin on a 1Mb rate network with unknow number of real controllers as well as simulator controllers.

In my server, I need to read messages from all of the channels connected to the server. Then I need to broadcast these messages to all of the channels beside the one they are come from.

Best regards,

Thang Nguyen

Link to comment

Thank Mark,

I guess I should do this for all of the channels connect to the server.

I just want to confirm that if this is a really good architecture for a server because this is a CAN server workin on a 1Mb rate network with unknow number of real controllers as well as simulator controllers.

In my server, I need to read messages from all of the channels connected to the server. Then I need to broadcast these messages to all of the channels beside the one they are come from.

Best regards,

Thang Nguyen

The only way to get the performance you are looking for is to use parallel tasks. You could have a task specifically for broadcasting the data to the other channels, one for reading the data and another for any internal processing that you might need to do. In addition you can have other tasks that work on other activities if needed. I certainly wouldn't try to do everything in a single state machine or event structure.

Link to comment

Hi,

I would like to know how to register for the event of receive data from data socket or TCP/IP. I have used normal read only. Currently I am working on a server which require both TCP/IP and socket and some other dll. I think I should use event in this case.

Please tell me how to do it. I haven't found any example yet.

Best regards,

Thang Nguyen

The constraints for the project might not allow this, but with LabVIEW DSC it is possible (and straightforward) to handle networked shared variable value change events. (This only helps if you can update the clients in your application to write to shared variables, of course.) Networked shared variables use a publish-subscribe paradigm, so if you just want to share broadcast data between clients this is a simple solution to implement.

It might be possible to simplify this even further depending on the messages you are sending. For instance, if every client can send and receive the same message set you might consider using a single shared variable and the object-oriented Command Pattern, passing along inside the particular command object an object as a data element that represents the particular client that is the source or destination of the message (if needed). I can explain further if this is of interest to you.

Link to comment
  • 4 weeks later...

Hi,

There is one thing I still not figure out is how I can send data to other clients? I belive that I cannot have the reference of other clients in one client. Inside the process of one client there should be 2 independent loops. One is to receive data, and one is to send data. Could you please tell me how I send data to the rest of client?

Best regards,

Thang Nguyen.

Link to comment
<BR>Hi,<BR>There is one thing I still not figure out is how I can send data to other clients? I belive that I cannot have the reference of other clients in one client. Inside the process of one client there should be 2 independent loops. One is to receive data, and one is to send data. Could you please tell me how I send data to the rest of client?<BR><BR><BR>Best regards,<BR>Thang Nguyen.<BR>
<BR><BR>It seems to me you are trying to implement something with the same goals as the Observer Pattern (a publish-subscribe communication paradigm).<BR><BR>NI provides an example of one way to implement a publish-subscribe system here: <A class=bbc_url title="External link" href="http://zone.ni.com/devzone/cda/epd/p/id/2739" rel="nofollow external">STM</A>.<BR><BR>Shared variables with the DSC module provide this built-in, and with the DSC module you can register for shared variable value change events.  (There are lots of other features, too.)  If this is an option, it is probably the simplest path to success.  We have found it works well.  The downside is that you don't have access to the internal workings.  The upside is that NI maintains it!<BR><BR>Paul<BR><BR>If you want to implement your own version of the Observer Pattern, I recommend checking out:<BR><A class=bbc_url title="External link" href="http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&s=books&qid=1261417852&sr=8-1" rel="nofollow external">GoF Design Patterns</A> (fantastic book!)<BR>or<BR><A class=bbc_url title="External link" href="http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124/ref=sr_1_2?ie=UTF8&s=books&qid=1261417852&sr=8-2" rel="nofollow external">Head First Design Patterns</A>.<BR><BR>(Somebody has already figured out how to do it--and do it well!)
Link to comment
  • 3 weeks later...

I use a producer-consumer with a message queue where the producer is an event loop and the consumer loop is also an FSM. When I need to send a tcpip message, I Q the appropriate message and let the consumer send the tcpip message and then return to an 'idle' state. Another loop handles the incoming tcpip messages. In my case the incoming and outgoing messages are very infrequent so I simply use functional globals to pass sets of data around. I have been using this method to communicate with several preexisting projects that use old MVME boards in a VME chassis and the only way I can communicate it to use tcpip.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.