Jump to content

tcp ip comunication between labview and c+++ application


aizen

Recommended Posts

Good morning

I have the following problem.

I'm studying the examples simple client.vi and server.vi.

My problem is that a LabVIEW 8.2 VI implemented to acquire data and to control an actuator

should send to and receive from another application written in C + + numeric data using tcp/ip connection on the same local PC.

The c++ program and the labview program have to first send or receive data and then run some specific function.

I would understand if the above examples can be used to send and receive data in labview program and if the c++ application can work using the same port on the same pc

by means of the tcp protocol to send to and receive data from the labview application

thanks

Link to comment

I would understand if the above examples can be used to send and receive data in labview program and if the c++ application can work using the same port on the same pc

by means of the tcp protocol to send to and receive data from the labview application

You can use TCP to send data between two programs on the same PC. The LabVIEW program and the C++ will use different ports because only one application can open a port at a time, but this is not a problem. You will want to pick one of the two applications to be your "server" and the other as a "client." The server opens a specific port and listens for a connection. The client connects to that port (which is not the same as opening it) to establish communication. The client is automatically assigned a random port when it opens the connection.

Link to comment

You can use TCP to send data between two programs on the same PC. The LabVIEW program and the C++ will use different ports because only one application can open a port at a time, but this is not a problem. You will want to pick one of the two applications to be your "server" and the other as a "client." The server opens a specific port and listens for a connection. The client connects to that port (which is not the same as opening it) to establish communication. The client is automatically assigned a random port when it opens the connection.

You are basically correct in what you are saying but not entirely accurate. Every established TCP connections actually consists of two port numbers that are the source and destination port numbers. This pair of port number along with the pair of IP addresses are used to uniquely identify every TCP connection. As you stated the server will establish a listener on a know port (see below regarding port number assignments) and waits for a connections. The client will use the server's known port as the connection's destination address and will generally choose a random port number for the source port number when it establishes a connection to the server. This pair of ports allows along with the source and destination IP addresses establishes a unique connection. This allows a server to have multiple connections open to one or many clients at the same time. To establish a connection on a single machine the client will attempt to open a connection using the server's known port number and either the machine actual IP address or the special address 127.0.0.1 which is the special address known as "localhost". In other words, this machine.

Using the LabVIEW TCP VIs unless the client application specifically specifies the source port a random port number will be chosen. This means the only thing the client will need to know is the IP address and port number of the server to establish a connection. Generally you should always allow the client to randomly select it's source port when establishing a connection. Only under rare situations do you need to specify the client's port number. You can run into trouble if you use a fixed port number for the client because you may choose a port number that already exists or more commonly will be unable to open a new connection using the same port server/client port pair. The TCP specification states that the port cannot be reused for at least 30 seconds. Windows generally sets this time at four minutes. So, if your application will be opening and closing connections to the server fairly quickly you will be limited by the wait time for tearing down a connection.

TCP port numbers:

PORT NUMBERS

(last updated 2010-01-15)

The port numbers are divided into three ranges: the Well Known Ports,

the Registered Ports, and the Dynamic and/or Private Ports.

The Well Known Ports are those from 0 through 1023.

DCCP Well Known ports SHOULD NOT be used without IANA registration.

The registration procedure is defined in [RFC4340], Section 19.9.

The Registered Ports are those from 1024 through 49151

DCCP Registered ports SHOULD NOT be used without IANA registration.

The registration procedure is defined in [RFC4340], Section 19.9.

The Dynamic and/or Private Ports are those from 49152 through 65535

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.