LBR iiwa TCP/IP communication issue

  • Hi everyone,


    I am working with KUKA LBR iiwa by using SunRise Workbench and I need to connect the robot with another device using a TCP/IP protocol. I am writing a TCP/IP server and a TCP/IP client using java sockets. Actually, when I use the robot as the server, I am able to establish a connection using my laptop as client. But when I try the opposite task (robot-client and laptop-server), it says "Connection timed out: connect".


    Is there anyone who can give me any advise?


    Thanks in advance,


    Here is the client code:


    public class LBR_Client {
    private PrintStream out = null;
    private BufferedReader in = null;
    @Override
    public void initialize() {
    Socket socket = null;
    try {
    socket = new Socket("172.31.1.14", 30001);

    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    out = new PrintStream(new BufferedOutputStream(socket.getOutputStream()), true);
    out.println("client message");


    System.out.print("server message: " + in);


    out.close();
    in.close();
    socket.close();

    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }


    @Override
    public void run() {
    }
    }


    And here's the server code:


    public class MyServer {
    public static void main(String args[]) throws IOException{
    Socket client;
    BufferedReader in = null;
    PrintStream out = null;
    try {
    ServerSocket server = new ServerSocket(30001);
    client = server.accept();
    server.close();
    in = new BufferedReader(new InputStreamReader(client.getInputStream()));
    out = new PrintStream(new BufferedOutputStream(client.getOutputStream()), true);
    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));


    String userInput;
    userInput = stdIn.readLine();
    out.println(userInput);

    System.out.print("Client message: " + in);

    stdIn.close();
    out.close();
    in.close();

    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }

  • Hi Giuseppe Capellacci,

    Quote

    I am writing a TCP/IP server and a TCP/IP client using java sockets. Actually, when I use the robot as the server, I am able to establish a connection using my laptop as client. But when I try the opposite task (robot-client and laptop-server), it says "Connection timed out: connect".


    Hm.. the communication should be "symmetric" feasible.


    I would check the Network/Firewall Settings on the Laptop, since a lot of those Firewall-Systems distinguish between outbound and inbound traffic - aka: who is the Server and who is the client.
    Therefore, as you open the socket ports in your Firewall, you can configure for "incoming" or "outgoing" in separate views.


    For an simple test: Deactivate the Firewall of the Laptop for the Duration of your test, and rerun the Client/Server Programs.



    A quick glance on your code: It seems ok, unless:
    I personally would not immediately close (server.close()) the Server socket directly after first Connection of the Client ("Server.accept()"), but keep the Server running in an endless Loop reentering "accept()" as soon as the Client finishes - this saves a lot of Manual "restart" work.


    Therefore: In your program, the Server MUST be started before the clienat - and each time a Client connects...
    ... you could reduce this pain..


    Hope that helps,
    DrG

  • You're closing the server socket, too early, before even reading from the input stream. And you're printing the object BufferedReader in, instead of reading from the stream. google some simple TCP server/client examples and build on them.


    Code
    1. System.out.print("server message: " + in);
  • Here's a simple example that works.



    Client on Robot:


    Server on PC:


  • Thanks kiiwa. However, the problem is still not solved.


    My code is the following:



    The code then throws the first exception.


    In attachment a Wireshark capture of the network.


    KUKA IP: 172.31.1.147
    PC IP: 172.31.1.50


    BR,


    Matteo

  • Solved, it was a problem with firewall rules.


    For the sake of clarity someone should or disable firewall or create an inbound policy that allows communication from iiwa port to the port of the laptop.

  • As a note on the same topic: port numbers are also a source of problems, you can only use port numbers between 30,000-30,010

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