LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Checking remote TCP connections

I have a computer that we will call A, and I want other computers (B, C, D, ...) to send data to a specific TCP port on A.  I have that working, but the problem I am having is that I want only one computer at a time to be able to send the data to A. 
 
For instance, if B is already communicating with A, I want C to throw an error.  I have ran some simple tests and it appears that B and C can write to the same port on A at the same time.  The port seems to create a buffer that collects the data from both computers. 
 
Is there a way to configure the port to be a single writer like you can in shared variables?  (By the way, i have tried the shared variable route but wasn't liking the communication speed.)
 
Or is there a way when I try to open a connection from B, C, ... that it checks to see if A's port is already connected to another computer?
 
I hope this A, B, C description isn't too confusing.
0 Kudos
Message 1 of 7
(3,473 Views)

Hi ejw,

if A is your server and you has a listener there, then you can close the listner as long as a computer is connected to it. So if B write data to A, destroy the listener. And if C try to connect to A, C get an error because the listener is not running.

Hope it helps.

Mike

0 Kudos
Message 2 of 7
(3,472 Views)
What you are seeing is the way TCP/IP is designed to work, and it sounds like you're trying to use it in the exact opposite way as they way it's supposed to work. Makes me wonder: why? Or, a better question: what are you trying to prevent? Is it an issue where you don't want crossed messages? In other words, are these other computers sending requests and you don't want the response to B to be sent to C? Or, is it that A is only "single-threaded" in its operation?
Message 3 of 7
(3,463 Views)
MikeS81,
 
Thank you.  I ran a couple of quick tests and it seemed to be behaving like I want.  It just didn't occur to me to close the listener. 
 
Also starting to realize tracking my errors will be crucial in this endeavor.
 
smercurio_fc,
 
I'm new to TCP, so I'm sure you are right about it working exactly how it was supposed to.   The reason it is probably confusing is because I'm trying to create a very impure pseudo-server/client set up.  
 
In this situation I want A to be single-threaded, but capable of switching from one computer to another after one closes.  Ultimately A will be controlling hardware, and I definitely don't want 2 different programs to trying to control the same hardware channel at the same time. 
 
Thank you both for your quick responses.
0 Kudos
Message 4 of 7
(3,448 Views)
Hi ejw,
attached you will find an example of a server which can only have one connection simultaneously.

Hope it helps.
Mike

Message Edited by MikeS81 on 06-10-2008 09:21 PM
Download All
0 Kudos
Message 5 of 7
(3,421 Views)
If you have some time, you might try and create a server - client structure, where you use a watchdog that also holds information about communication status and who has the ability to control the server (use the IP or DNS name as an ID or something). The clients that are not in control of the server must then stop sending data to the server that can control the hardware (the server could also have a failsafe to discard control messages sent from other clients that are not in control), but they are still able to recieve data and other messages from the server, so if a other client does changes to the server, the server has the ability to also update the clients without control with that exact changes.
0 Kudos
Message 6 of 7
(3,393 Views)

Corny,

That sounds like a best practice scenario so I would definitely want to look into it.  But at my current understanding of TCP it is beyond me.  Are there any examples you could point me towards?

As it stands right now, I have something working but under worst case scenarios when 200 ports are suddenly written to there is a huge lag caused by tripping the active listeners and closing them before I can start reading.  If anyone has been down this road I would appreciate the help. 

0 Kudos
Message 7 of 7
(3,374 Views)