Jump to content

Multiple connection from the same IP to the same IP/Port


Recommended Posts

i apologize if this topic has been brought up before; which means I fail at searching! :book:

I am trying to figure out how to create a vi that can accept TCP connection from multiple sources on the same IP Port, and from the same IP address.

I am trying to create a logging program that will accept TCP connections from multiple sources (same or different PCs), each with difference parameters and as a result different log files. The post connection that is easy, but I am having a problem with the accepting multiple connections to the same TCP port. I was reading that the TCP protocol allows for connections from different IPs to the same port, but I need to handle connection from the same IP also. EX: I have 2 test programs on the same PC, each needs to log it's actions/errors/whatever. How to I establish the connection?

Link to comment

I had the same problem using the same IP and port for receiving as well and transmitting in UDP.

Adding the following to the Labview INI file will allow you to do it in windows, but I can’t promise it will work in Linux.

SocketSetReuseAddr=TRUE

Don’t forget to add the INI file to your installer when you create the installer, or your be wondering why it won’t after you install it.

Link to comment

I think you've misunderstood something slightly. Accepting multiple connections on a single port is the same regardless of whether the connections originate from a single IP address or different addresses. Outgoing connections are assigned ports (usually automatically), and so long as the port/IP address combination is unique, there should be no problem.

To accept multiple connections you need to understand the difference between a listener and a connection. In newer versions of LabVIEW (2011, haven't checked 2010), TCP Listen has a listener output. In older versions (LabVIEW 2009, maybe 2010) you need to use TCP Create Listener and Wait on Listener yourself. When Wait on Listener returns a new connection, you need to handle that new connection and continue listening on the listener for more connections. There are a couple of ways to handle this; the common ones I know of are 1) dynamically launch a VI to handle the new connection, or 2) add the new connection to an array of connections in a separate loop, and iterate through the connections continuously, sending or receiving data as appropriate on each one.

You may find this thread about listeners and connections helpful. It also explains why you should not open and close the listener for every connection, in case you're doing that. http://forums.ni.com/t5/LabVIEW/TCP-IP-feature-or-bug/td-p/832692

  • Like 2
Link to comment

Check out the XML-RPC Server in the Code Repository for an example of a server that can accept mutiple clients ( ) . You shouldn't have any problems accepting mutiple connection requests from the same IP to the same server port, as the server should establish a unique connection (socket) for each request.

Mark

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.