Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection refused:connect #66

Open
mandar-bhide opened this issue Nov 16, 2021 · 1 comment
Open

Connection refused:connect #66

mandar-bhide opened this issue Nov 16, 2021 · 1 comment

Comments

@mandar-bhide
Copy link

My code is:

package mavlink;

import java.io.EOFException;
import java.io.IOException;
import java.net.Socket;

import io.dronefleet.mavlink.Mavlink2Message;
import io.dronefleet.mavlink.MavlinkConnection;
import io.dronefleet.mavlink.MavlinkMessage;

public class MainClass {
	private static void print(Object o) {
		System.out.println(o);
	}
	public static void main(String[] args) {
		try(Socket socket = new Socket("127.0.0.1", 5760)){
			MavlinkConnection connection = MavlinkConnection.create(socket.getInputStream(),socket.getOutputStream());
			MavlinkMessage message;
			while((message = connection.next())!=null) {
				if(message instanceof Mavlink2Message) {
					print(message.getPayload());
				}
			}
		}catch(EOFException eof) {
			eof.printStackTrace();
		}catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}
}

Terminal output is:

java.net.ConnectException: Connection refused: connect
	at java.base/sun.nio.ch.Net.connect0(Native Method)
	at java.base/sun.nio.ch.Net.connect(Net.java:503)
	at java.base/sun.nio.ch.Net.connect(Net.java:492)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
	at java.base/java.net.Socket.connect(Socket.java:648)
	at java.base/java.net.Socket.connect(Socket.java:597)
	at java.base/java.net.Socket.<init>(Socket.java:520)
	at java.base/java.net.Socket.<init>(Socket.java:294)
	at mavlink.MainClass.main(MainClass.java:16)

I have connected APM 2.8.0 via USB to windows 10 with intel i7-8550u. I am looking forward to deploy the code on a raspberry pi.
Actually I recieved similar error with dronekit python so shifted to Java. But stuck at same point.
Thank you.

@seanrowens
Copy link

Based on your description, your computer is connected to your flight controller over a serial connection. But your code is trying to use a TCP socket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants