×

INDI Library v2.0.6 is Released (02 Feb 2024)

Bi-monthly release with minor bug fixes and improvements

INDI4Java

  • Posts: 13
  • Thank you received: 1

INDI4Java was created by Jat

I try to write a client with INDI4Java. I have checked the tutorials and the IPARCOS-master also, but I have a problem to import INDI libary.
I use Eclipse. I have tried to import all *.jar from i4j-all-in-one-1.50-SNAPSHOT, but it could'nt help.

How can I import INDI4Java libary? And is there any other examples?

Thank you,
Tamás
8 years 1 month ago #6937

Please Log in or Create an account to join the conversation.

  • Posts: 456
  • Thank you received: 76

Replied by Derek on topic INDI4Java

Are you using maven to mange dependencies?
8 years 1 month ago #6940

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 1

Replied by Jat on topic INDI4Java

No, I'm not.
8 years 1 month ago #6941

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 1

Replied by Jat on topic INDI4Java

When I try to connect INDI Server, I have got this fault:

java.net.MalformedURLException: unknown protocol: indi

What should be wrong?

Thank you,
Jat
8 years 1 month ago #6973

Please Log in or Create an account to join the conversation.

  • Posts: 456
  • Thank you received: 76

Replied by Derek on topic INDI4Java

Could you post the full stack trace and your code. I'll try to help.
Derek
8 years 1 month ago #6975

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 1

Replied by Jat on topic INDI4Java

My code is:

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;

import org.indilib.i4j.client.INDIDevice;
import org.indilib.i4j.client.INDIProperty;
import org.indilib.i4j.client.INDIServerConnection;
import org.indilib.i4j.client.INDIServerConnectionListener;
import org.indilib.i4j.client.INDIDeviceListener;
import org.indilib.i4j.client.INDIPropertyListener;


public class IndiClient implements INDIServerConnectionListener, INDIDeviceListener, INDIPropertyListener
{
private INDIServerConnection connection;

public IndiClient()
{
String host = "localhost";
int port = 7264;

connection = new INDIServerConnection(host, port);
/*
connection.addINDIServerConnectionListener(this);

try {
connection.connect();
connection.askForDevices(); // Ask for all the devices.
} catch (IOException e) {
System.out.println("Nem lehet kapcsoldni a szerverhez.");
System.exit(-1);

}

*/
}


@Override
public void connectionLost(INDIServerConnection arg0) {
// TODO Auto-generated method stub

}

@Override
public void newDevice(INDIServerConnection arg0, INDIDevice arg1) {
// TODO Auto-generated method stub

}

@Override
public void newMessage(INDIServerConnection arg0, Date arg1, String arg2) {
// TODO Auto-generated method stub

}

@Override
public void removeDevice(INDIServerConnection arg0, INDIDevice arg1) {
// TODO Auto-generated method stub

}


@Override
public void propertyChanged(INDIProperty<?> arg0) {
// TODO Auto-generated method stub

}


@Override
public void messageChanged(INDIDevice arg0) {
// TODO Auto-generated method stub

}


@Override
public void newProperty(INDIDevice arg0, INDIProperty<?> arg1) {
// TODO Auto-generated method stub

}


@Override
public void removeProperty(INDIDevice arg0, INDIProperty<?> arg1) {
// TODO Auto-generated method stub

}




}


The exception:

Exception in thread "main" java.lang.IllegalArgumentException: illegal indi url
at org.indilib.i4j.client.INDIServerConnection.<init>(INDIServerConnection.java:119)
at IndiClient.<init>(IndiClient.java:22)
at Main.main(Main.java:6)
Caused by: java.net.MalformedURLException: unknown protocol: indi
at java.net.URL.<init>(URL.java:414)
at java.net.URL.<init>(URL.java:303)
at org.indilib.i4j.client.INDIServerConnection.<init>(INDIServerConnection.java:117)
... 2 more


Thank you very much!
8 years 1 month ago #6976

Please Log in or Create an account to join the conversation.

  • Posts: 298
  • Thank you received: 46

Replied by Markku on topic INDI4Java

Hi..
I don't know much about java but the line :
int port = 7264;
Shouldn’t it be 7624 ??

Br
/Markku
8 years 1 month ago #6977

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 1

Replied by Jat on topic INDI4Java

7264 is working also.
I have tried it with Android client, and it was working.

Thank you,
Jat
8 years 1 month ago #6978

Please Log in or Create an account to join the conversation.

  • Posts: 456
  • Thank you received: 76

Replied by Derek on topic INDI4Java

Java needs to have a handler registered for custom protocols.
I'm not 100% familliar with this library but the constructor below will work in your code.
Should probably move the setting of the StreamHandlerFactory into a static block somewhere as it only needs to be done once.
public IndiClient() {
        String host = "localhost";
        int port = 7624;
        URL.setURLStreamHandlerFactory(new INDIURLStreamHandlerFactory());
        connection = new INDIServerConnection(host, port);
    }
The following user(s) said Thank You: Jat
Last edit: 8 years 1 month ago by Derek.
8 years 1 month ago #6979

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 1

Replied by Jat on topic INDI4Java

It was working.

Thank you very much!
Jat
8 years 1 month ago #6980

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 1

Replied by Jat on topic INDI4Java

If I use URL.setURLStreamHandlerFactory(new INDIURLStreamHandlerFactory());, I have an other exception.

This code is usefull: static { INDIURLStreamHandlerFactory.init(); } (based on Remote Observatory)

Thank you,
Jat
8 years 1 month ago #6982

Please Log in or Create an account to join the conversation.

Time to create page: 1.086 seconds