From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreading tcp connection

Solved!
Go to solution

Hi,

I'm building a labview server that communicates with a java client.

The communication works but I have 2 problems:

- Labview writes only string via tcp, so I cast Double to String, but when I try to read it reads a wrong value. Someone knows what kind of stream I can use in java?

- How can I obtain a multithreading server? After the first read I need to wait for other events, that will arrive during the execution of the program.
  I tried with two while loop with 2 tcp listener on different ports, but it didn't work.

Thanks for your help,
Veronica

0 Kudos
Message 1 of 12
(3,650 Views)

@Skeggy88 wrote:

Hi,

I'm building a labview server that communicates with a java client.

The communication works but I have 2 problems:

- Labview writes only string via tcp, so I cast Double to String, but when I try to read it reads a wrong value. Someone knows what kind of stream I can use in java?

- How can I obtain a multithreading server? After the first read I need to wait for other events, that will arrive during the execution of the program.
  I tried with two while loop with 2 tcp listener on different ports, but it didn't work.

Thanks for your help,
Veronica


Hi Veronica,

 

It could be the byte order that messes it up for you?

Try to flip the order before you send it and see if it works?

 

A few LabVIEW/Java links:

http://lavag.org/topic/2723-tcpip-java-labview/

http://forums.ni.com/t5/LabVIEW/problem-with-tcp-server-sending-data-to-java/td-p/1102302

 

An example object oriented threading example:

https://decibel.ni.com/content/docs/DOC-24498

 

What you can do there is spawn/create a new thread with each incoming connection.

 

Br,

 

/Roger

 

0 Kudos
Message 2 of 12
(3,648 Views)

I had already seen these examples on java. Tomorrow I will try to reverse data, because here in Italy it's late.

Then, I don't understand this multithreading VI... I thought that I have to do something simpler.
I attach my idea. Is it totally wrong?

0 Kudos
Message 3 of 12
(3,640 Views)

@Skeggy88 wrote:

I had already seen these examples on java. Tomorrow I will try to reverse data, because here in Italy it's late.

Then, I don't understand this multithreading VI... I thought that I have to do something simpler.
I attach my idea. Is it totally wrong?


I think you are using a Apache Tomcat/proxy port?

Perhaps you should move to ports in the range: 

http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

 

It's common to have an inner tcp read loop, and to go back listening when your tcp session ends.

http://www.ni.com/white-paper/3982/en

http://www.ni.com/white-paper/2710/en

 

Br,

 

/Roger

 

0 Kudos
Message 4 of 12
(3,634 Views)

I read these examples, but connections are put in a queue and I need to manage 2 connection in the same moment.

I attach a little "summary" of my program.
I need to:

- Read the command "ON0", create a file and acquire data using a DAQ. These data are written on file and also via tcp, so the connection must be active.

- Wait for events. Events will activate the case structure that writes event on file.

Can someone explain me clearly what I need to do?
I'm a beginner with labview but I have to finish this program this week because I must send my thesis to my professor.

Thank you and sorry for my english.

0 Kudos
Message 5 of 12
(3,607 Views)

Is there anyone?

0 Kudos
Message 6 of 12
(3,585 Views)

If you want N clients to each communicate with a dedicated instance of your server, then you must the set the server VI to be "re-entrant". Then, when a client connection is accepted, you spawn a new server instance and pass it the connection reference.

0 Kudos
Message 7 of 12
(3,575 Views)

What's the meaning of "re-entrant"??

0 Kudos
Message 8 of 12
(3,564 Views)

Re-entrancy means the VI can be "cloned" aka "spawned", that is, multiple copies of the VI can be in memory at the same time. You can set this property under "File...Properties...Execution (Reentrancy). Since you want each server instance to have its own data (not shared), use the "Preallocated clone" option.

 

The way I did this was to have a listener VI that dynamically calls the server VI when a connection is accepted. The listener VI passed the connection reference to the new server instance.

0 Kudos
Message 9 of 12
(3,557 Views)

Hi,

thanks for your reply.

I try to follow your advice and I did the "complete program" re-entrant.

I attach the server, but the tcp listener stops the execution. 

What's wrong? I don't know what to do Smiley Sad

0 Kudos
Message 10 of 12
(3,541 Views)