LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Tcp error 66, ghosts listener

I use a server-client architecture using tcp-ip connections.

If I listen on server for a connection and a client ask for a connection, then I need to close the connection on client.

If the client close for any reason, then the server close the connection and listen again for a new connection on the same port and the same address.

If the client doesn't close the connection, then there is a strange behaviour:

- if the server doesn't listen, then the client connect to a ghost listener.

- if the client doesn't ask for a connection, the listener creates a connection and then it receives 66 error.

How could I be robust to a client or server crashes?

0 Kudos
Message 1 of 3
(2,889 Views)

Can you share your code? That would help identify the specific problem you're having. Your "ghost" listener is not a ghost at all, it's normal behavior that allows your server to accept multiple connections on the same port. If you only want to allow one connection at a time, close the listener after the connection is established. You may need to use TCP Wait on Listener instead of TCP Listen to avoid errors.

 

My TCP code, which does accept multiple connections, usually uses a structure like this:

TCP Server.png

The loop at the bottom continuously accepts new connections on the listener. The upper loop maintains an array of connections, and continuously loops through all open connections looking for data on each one. It also tracks the last time it received a command on each connection. If it's been more than an hour since it last received a command, it closes the connection. This isn't strictly necessary, but it's appropriate for my application. I've used this design in multiple applications and it's robust. It may be overkill for your application if you only need to maintain one connection at a time.

0 Kudos
Message 2 of 3
(2,861 Views)

I expect that you've run into the same issue which I ran into a few years ago - being somewhat confused by how TCP Listen behaves. Essentially, it creates a "listener" (a concept which isn't really explained anywhere) and as long as that listener exists, the open primitive on the other side will successfully open a connection. That would be your ghost listener. Nathan also helped me understand this back then, so I would suggest following his advice on this.


___________________
Try to take over the world!
0 Kudos
Message 3 of 3
(2,814 Views)