I run a java program during the launch of Raspberry (which includes Raspbian). I used the file /etc/rc.localto do this and it works correctly (I also tried the solution /etc/init.d/, but I prefer the other). I run my raspbian directly in console mode, so I can see the output of my program.
My problem: By manually launching my application, it works well. Starting automatically at boot, it throws a Bind exception: cannot assign the requested address.
Program launch
In the /etc/rc.local file, I wrote this line. It runs a script that runs my .jar program.
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
/home/pi/Documents/DinnerTimePi/startApp
exit 0
My startApp script :
#! /bin/sh
cd /home/pi/Documents/DinnerTimePi/
date >> testStart.txt
java -jar DinnerTimeServer.jar
exit 0
Server initialised at : 192.168.1.35 address and : 35150 port.
_ #(Waiting for client to connect)
Java
Java- - ServerSocket, , .
public class TimeServer {
static private TimeServer instance;
static private int port = 35150;
static private String host = "192.168.1.35";
private ServerSocket server = null;
protected TimeServer(String pHost, int pPort){
list = new LinkedList<ClientProcessor>();
host = pHost;
port = pPort;
try {
server = new ServerSocket(port, 10, InetAddress.getByName(host));
} catch (BindException bind){
bind.printStackTrace();
System.exit(1);
} catch (UnknownHostException hoste) {
hoste.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
, IP- 192.168.1.35, , .
, , , 6543 35150. : , .
, .
[...]
[ OK ] Reached target Network is Online.
Starting LSB: Start NTP deamon...
[ OK ] Started LSB: Start NTP deamon.
java.net.BindException: Can't assign requested address
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at server.TimeServer.<init>(TimeServer.java:57)
at server.TimeServer.getInstance(TimeServer.java:32)
at server.Main_Server.main(Main_Server.java:12)
[ OK ] Started /etc/rc.local Compatibility.
Starting Terminate Plymouth Boot Screen...
[...]
, , - , , , .
root.
, , , .
!:)
( , , github, autolaunch)