LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP listen is giving error 56

Hi,

 

I have a simple TCP Server Client Program on two PCs. First PC which is the client, I have programmed a simple TCP open connection, then a while loop in which there is a button, a case structure and inside the case structure true, a TCP write and outside the while loop, TCP close. TCP open i gave the IP address of the second or server PC and its port number 45321. And I run this program, it works perfectly without any error. This part is ok, since I have done this in the past with other devices. But now the server is not another device. Its another PC with labview and I have to program the server side myself for the first time. So I did this. 

govindsankar_0-1723122943628.png

As you can see, I have created a TCP Listen and I have given the same port number which is 45321, because as I know, the client will write on this port and the server should be listening on this port and when something is written we can use TCP read to read that out. This is what I assumed. But the program is not even entering the while loop. It gets stuck on TCP listen, and then I gave a timeout of 5 seconds, and after 5 seconds it generates error 56. What is the problem here. Why is this not working. Thank you. 

 

0 Kudos
Message 1 of 13
(880 Views)

You get a timeout error. First we need to know what part is generating it.

Your TCP listener times out if no connection is made within 5 seconds of program start (5000ms).

How often is data received? If you set the timeout for reading to 5 ms and it takes longer than that, you'll get a timeout error, of course

 

As always, we can't really debug images. What code is used in the sender?

 

Somehow, It feens like UPD would be a better choice, depending on the requirements.

0 Kudos
Message 2 of 13
(850 Views)

Ok, I have uploaded the code instead of picture and description. The timeout error is generated by TCP Listen.  TCP Listen is outside the while loop. So I dont set timeout, it doesnt even enter the loop. It waits for ever. Data is send only once when I press the button.Sorry the UDP cannot be used. It has to be TCP because of some requirements. Thank you. 

Download All
0 Kudos
Message 3 of 13
(816 Views)

@govindsankar wrote:

he timeout error is generated by TCP Listen.  TCP Listen is outside the while loop. So I dont set timeout, it doesnt even enter the loop. . 


Incorrect! TCP listen has a 5 second timeout wired!

 

altenbach_0-1723215783905.png

 

 

None of this looks right. Why don't you start with the shipping examples?

 

(... and please (please!!!) don't maximize the front panels and diagrams to the screen. Nobody want to stare at a monitor with mostly whitespace! while being prevented to look at other windows, such as the help window that you need). I also doubt you need a greedy loop in the client.

0 Kudos
Message 4 of 13
(796 Views)

I didnt set timeout in the beginning. The program was never entering the loop. It just stayed frozen at TCP listen. Then I set timeout, thats when error came and I shared that code with you. Of course I know there is a timeout of 5 seconds there. I am the one who set it. You said none of this looks right. What do you mean? Why is TCP listen unable to get a connection with a port. I checked the examples. The examples work on the same PC, with local host. So that works. But what I am trying to do is two different PCs. 

 

Little more clarification. I have a client PC sending a simple string to my server PC. The client PC and server PC are connected through a ethernet switch and I have two static IPs in both PCs set up. So the client PC works perfectly fine. I have a software CurrPorts installed in my server PC to see the all data incoming and outgoing and it shows the data that is coming from my client PC, so that part is ok.

 

The problem is why isnt it reading in server PC. So why does TCP Listen not work when its two computers. In the example, I run the server first and TCP listen waits for a connection and when I run the client immediately TCP listen will get it and start working. But here in my program, I run TCP listen without timeout and it waits, then I run Client in the other PC and client sends data where TCP listen here will be still waiting. I dont understand. 

 

Also in between, I understood labview was using the wifi IP as the local IP.  I used the string to IP without giving input and read out its output which will be the local IP and the result was wifi IP. Then I disconnected the wifi to see which one is it now and then I found out it was the correct IP which was the ethernet IP. But still TCP Listen is just waiting. Its not connecting. I also tried wiring the net address to TCP Listen and then its immediately giving an error 60 TCP Create Listener in Internecine Avoider.vi->TCP Listen.vi. What is the issue here? Why isnt TCP listen able to read the incoming connection. As I said earlier the software CurrPorts confirm that there is data coming from client PC. But CurrPorts is also showing that in the server labview.exe is listening to port which I entered by the local address is 0.0.0.0 instead of my IP address. This is the same value even after removing wifi. 

What is the problem here? What am I missing. Thank you. 

0 Kudos
Message 5 of 13
(736 Views)

I ran the the simple TCP project from the examples. You can find it in examples under networking, under TCP & UDP as Simple TCP.lvproj. I ran the program and it works. In the program its trying to connect to port 6340 of local host in client and listening to 6340. Local host as you know would be 127.0.0.1 in every PC. So that works. I changed the program from local host to a static ip address I set and to one of the open ports under that IP and in server I tried to listen to that port and when I run the program the client works. Its connecting to static IP and open port correctly, but my server program doesnt work. TCP listen just keeps waiting for a connection and then timesout. But client had already established a connection but server is unable to listen to it. Why is this? What is the problem that is preventing TCP listen from listening to the connection made to my static IP. I also watched a youtube video and did the exact the same program in the youtube video to see. 

https://www.youtube.com/watch?v=fJ_fEoBHoFw&list=PLj94YLX50Wtn7XvVG4Pa58M0HGs4o62r1&index=1

In the youtube video the person is able to make it work, but when I do it in my PC, same problem. Client makes connection but TCP listen cannot listen to that connection in server. I have uploaded that code here as well. Can someone explain to me why is this so? Thank you. 

0 Kudos
Message 6 of 13
(714 Views)

If your TCP Client is connected, and your TCP server do not get any connections. Then your TCP Client is connected something else. And your Client can only connect to one "server". 

 

Make sure that your client IS connected to something, and then find out what it is connected to. 

0 Kudos
Message 7 of 13
(679 Views)

I found out the problem was port. So I am not sure how port works. So the port which I was working on earlier didnt work. But my colleague came and suggested 80 which is the https port and is always open and it worked. And then my colleague was saying that there are different ports used by labview and I need to try one of them, I dont understand how that is. So I picked this port 45321 by using netstat -ano and my colleague is saying maybe labview doesnt connect to that. So I did this new way where I wrote a seperate client server program just for connection, where I used a service name on Wait on Listener and gave port as 0 to get a random port. And I got that port as 58411. Now I used 58411 on my original progam and it worked. So 58411 is working.

 

So this comes to the initial issue which made me work on all this example in the first place. And that is connecting between two PCs. So now client is another PC and server is in this PC. So I gave my IP address and port number 58411 to the client PC and now client PC is not connecting. This was working when both client and server were in same PC, but now when I changed client to a different PC it is not working . If I use the 45321 from earlier then client will connect but server wont listen to it, doesnt matter if client and server are in two pcs or same pc, client will connect to 45321, but server will not listen in either case. If i use 58411, not even client is connecting, but 58411 will work when client and server are both on same PC and in this condition both client will connect and server will listen. So now I am not sure, how do I find the correct port number for working with two different PCs. Are there special port numbers for labview. This is really confusing. Thank you. 

0 Kudos
Message 8 of 13
(672 Views)

You are making a mess of this and are trying various things and drawing wrong conclusions. It would also appear that you ignore some of the basic error handling techniques. Information like "It doesn't work" usually means you are NOT observing what doesn't work nor which function returns an error and what that error is. If you would look at that you can usually draw much more precise conclusions than "It doesn't work!"

 

First, a port on a PC can only be used once at the same time. So if port xyz is already used by some service, trying to open a listener on that port fails and the Create Listen node will return an according error. If you specify a port number 0 on Create Listener, the OS will look for an available port and use that. If you also specify a service name (a string value wired to the service name input) LabVIEW will also register the according port in the NI service locater.

 

Now on your client side you need to specify the correct IP address (from the computer on which the Create Listener was executed) and the port number that was returned by the Create Listener node, or alternatively the service name you specified. This MUST be the port number returned by the Create Listener node, not some port number used by earlier trials on your local computer. Consider the port number like the house number under which your server runs. If that server was created with port number xyz and house number xyz is not already occupied by someone, it resides in house number xyz and not some other house in that street. If it was created with port number 0, Windows walks down the street and looks for a free house and puts that server in that house and returns the house number it put the service in to LabVIEW and LabVIEW gives you that number through the "port number" output of the Create Listener function.

 

In addition, if you specify a "service name" on Create Listener, LabVIEW itself registers the resulting port number under that name with the NI service locater on that computer.

 

For your TCP Connect function you then can either use the port number that Create Listener returned, or you can instead wire a string to the "remote port or service name" input. If you specify a port number it will simply try to connect to that port number, if you specify a service name LabVIEW will query the NI service locater on the remote computer for the service name and use the according port number to connect to the server.

 

It's important to look at any returned error. If one of the functions indicates an error it is usually futile to try anything more. Instead you need to observe the error and what it indicates and only after that function is successful can you go further and test the next step.

 

If you did everything correct and it still doesn't work there are several things that could go wrong. First port numbers below 1000 are privileged, if you try to specify such a port on Create Listener it will fail unless you have administrative privileges. Second you can not create a listener on a port that is already used. Create Listener should return an according error in both of these cases. Third you may have fire walls that simply capture connections. It is usually the nature of a fire wall to return as little feedback as possible to a client trying to go through it. This usually means that it will either simply drop connections right away, which should give an error in the according LabVIEW TCP Connect node, or it may actually accept and intercept the connection and route it into nono land where any incoming data is simply swallowed and no data whatsoever is returned. This last one is an interesting way to let a maleficent actor run in the dark about what is going on.

 

But observe the error cluster, look at the error number and interpret it accordingly. This is the first step in starting to debug things. Without error information it is simply impossible to make any intelligent guess if you did something wrong, Windows or LabVIEW is trying to play with you (very unlikely), or a third party such as a fire wall is intercepting something.

Rolf Kalbermatter
My Blog
Message 9 of 13
(665 Views)

First of all using the create listener node and service name. As I mentioned. I already did that, i did it again and got the port number 59233. As you said "LabVIEW itself registers the resulting port number under that name with the NI service locater on that computer", so using service name on two different computers wont work. I actually tried to see if it does and I found out it doesnt. So I did it in the same PC to get 59233. Then I wired 59233 and server IP address to TCP open connection in client PC and it waits for sometime and gives error. LabVIEW program in my server PC is saying 59233 is open, but client PC cant connect. I did exactly what you said.  The error it gives is 56. 

 

Now in the other condition when I use a portnumber from my command window and using command netstat -ano, then I get some open ports in server pc. I tried some of them, one for example is 45321. So I used 45321 and server IP to TCP open connection in client PC and then it connects. But now in server PC, the TCP Listen is not listening. So if i wire -1 to timeout, it just waits for ever and i wire a certain time then after that time, timeout error will be given. 

 

So the port number given by labview in server PC, client PC cannot connect to it and the port number given by command window of server PC, client PC can connect, but then server PC cannot listen to that port. What kind of problem is this? It doesnt make any sense. This is the issue. 

 

 

0 Kudos
Message 10 of 13
(652 Views)