Background Task TCP/IP will not reconnect after synchronization

  • I have written up a TCP/IP Background Task. The robot is acting as the server and I am trying to constantly listen to incoming clients. I am currently getting an error every time I synchronise the robot with the Kuka Sunrise Workbench. The error seems to be that when I reconnect I am unable to as the Socket is already Bound. This obviously means I am not closing the socket. But I am not too sure how to close the socket on an abrupt termination of the TCP/IP background task, especially when I hit the task to stop or when I go to synchronise.


    Is there a way that I could attempt to close the socket before the background task is shutoff? OTherwise I have to power cycle after everytime I synchronise.

    This is my first time writing TCPIP. So I probably havent written it in the most ideal way either. But like I said Im trying to close the serverSocket before it is synchronised. I am not too familar with how a cyclic background task comes to an end or if there is a procedure/function I need to write that is called before it is abruptly closed.

  • You could try override dispose() method in your backgroundTask.


    Code
        @Override
        public void dispose() {
            ServerSocketClose_();
            
            super.dispose();    // not so sure this is needed. just my habit.
        }


    And this dispose() method will be called when you press the stop button of the backgroundTask on HMI.

    - you could do it by manually pressing this stop button, or other way to directly call dispose() when you need. ("END" packet from a client or so)

    However, You still need to stop-call dispose()- it before synchronizing.

    I experienced a bug-ish reaction when I try synchronize project without manually stopping a background task.

    It seems the instance is not properly disposed if it the dispose() method hasn't been explicitly called.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account
Sign up for a new account in our community. It's easy!
Register a new account
Sign in
Already have an account? Sign in here.
Sign in Now