Login  
Search All Forums
Dart Home | PowerTCP Sockets for .NET | Custom Development Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
AuthorForum: PowerTCP Sockets for .NET (Secure and Standard)
Topic: Redundant worker thread creation
addingon

From: USA
Posts: 7
Member Since: 04/05/06
posted January 18, 2014 4:41 PM

Hi,

In V4.4.8 Sockets for .NET, would there be any problem with redundant calls to the same data marshal code, prior to that marshalling taking place? For instance, TCPSocket.Marshal(TCPSocket.ReadToDelimiter(LANRXDelimiters), "", Nothing) would get called on a new TCPSocket.Start thread more than once before data actually arrived. Is there any harm in that (resources used, etc.) or does the library know internally that the same ReadToDelimiter method is still pending data, so it just ignores the new call?

Thanks,

Ray
Add-On Technologies, Inc.
Mike Baldwin (Admin)



From: Rome, NY USA
Posts: 114
Member Since: 04/11/00

Extra Support Options
Custom Application Development

posted January 20, 2014 9:08 AM

Hi Ray,

TCPSocket.ReadToDelimiter() will block until there is data on the socket that matches the search criteria, then will proceed. Does this answer your question?
Nick B (Admin)

From: Utica, NY USA
Posts: 619
Member Since: 05/25/10

Extra Support Options
Custom Application Development

posted January 20, 2014 9:45 AM

Hello Ray,

To add onto that: the Marshal method is a 'dumb' method; it does not ignore or delay raising events on the main thread when it is called. Unless ReadToDelimiter throws an exception (in which case, the application won't get to the Marshal call), it won't return until the specified delimiter is found; can you clarify what you're seeing that indicates that the method is called more than once before data arrives?

There shouldn't be any problem with redundant calls to it though; the Data event will just be raised however many times that Marshal overload is called. While it does use some resources to transfer the data between threads, it shouldn't affect the performance of your application unless you need to eke out every optimization possible.
addingon

From: USA
Posts: 7
Member Since: 04/05/06
posted January 20, 2014 3:43 PM

Thanks, Nick.

So a redundant Marshal method call will fire the Data event as many times as the redundant call had occurred, once a delimiter is found? I'm best to go back to the method I was using to prevent redundant calls (using a flag to prevent duplicate calls) since I don't want duplicate data events with the same data. The duplicate marshal calls could occur due to the possibility of async data arriving (not requested) and also commands sent that elicit response data.   

Regards,

Ray
  




Nick B (Admin)

From: Utica, NY USA
Posts: 619
Member Since: 05/25/10

Extra Support Options
Custom Application Development

posted January 20, 2014 4:21 PM

Hello Ray,

I think it would be best to separate the behavior of Marshal and ReadToDelimiter to keep things clear:

Marshal is an immediate call, it has no special behavior. The Marshal overload that you're using will raise the Data event when Marshal is called, every time it is called.

ReadToDelimiter will return when the specified delimiter is found (the data that it read is removed from the TCP socket, and will not be seen by a subsequent call to ReadToDelimiter). An exception will be thrown in circumstances such as when no data was received within the timeout period.

If this doesn't help resolve your issue, can you explain the exact behavior you're observing? None of what you've described should be causing 'duplicate data events with the same data' unless your server is sending the same data twice.
addingon

From: USA
Posts: 7
Member Since: 04/05/06
posted January 20, 2014 5:11 PM

Hi Nick,

I was making this more complicated than it needs to be, by adding the Start thread with Marshal/ReadToDelimiter after my various TCP writes. I moved the Start thread call to the TCP Data event and it just fixed everything.

Thanks again for your help!

Regards,

Ray
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX