roumei Active Member Licensed User Dec 28, 2021 #1 I'm trying to run Erel's HelloWorld Example on an Amazon EC2 instance. This is what I did: 1) Create the EC2 instance, open port 80 (at least I think I did, see image) and install Java. 2) Compile the B4J project with port number 80 and copy it together with the www directory to the Home directory on the EC2 instance. 3) Run the jar file with: B4X: java -jar /home/ec2-user/HelloWorld/HelloWorld.jar This produces the following error. Does anybody have an idea what the problem might be? B4X: main._appstart (java line: 55) java.net.SocketException: Permission denied at java.base/sun.nio.ch.Net.bind0(Native Method) at java.base/sun.nio.ch.Net.bind(Net.java:455) at java.base/sun.nio.ch.Net.bind(Net.java:447) at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227) at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:80) at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:340) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:308) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.server.Server.doStart(Server.java:398) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:220) at b4j.example.main._appstart(main.java:55) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109) at anywheresoftware.b4a.BA.raiseEvent(BA.java:96) at b4j.example.main.main(main.java:28) main.main (java line: 28) java.lang.RuntimeException: java.net.SocketException: Permission denied at anywheresoftware.b4a.BA.raiseEvent2(BA.java:138) at anywheresoftware.b4a.BA.raiseEvent(BA.java:96) at b4j.example.main.main(main.java:28) Caused by: java.net.SocketException: Permission denied at java.base/sun.nio.ch.Net.bind0(Native Method) at java.base/sun.nio.ch.Net.bind(Net.java:455) at java.base/sun.nio.ch.Net.bind(Net.java:447) at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227) at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:80) at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:340) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:308) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.server.Server.doStart(Server.java:398) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:220) at b4j.example.main._appstart(main.java:55) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109) ... 2 more Attachments EC2_Security.PNG 36.9 KB · Views: 534
I'm trying to run Erel's HelloWorld Example on an Amazon EC2 instance. This is what I did: 1) Create the EC2 instance, open port 80 (at least I think I did, see image) and install Java. 2) Compile the B4J project with port number 80 and copy it together with the www directory to the Home directory on the EC2 instance. 3) Run the jar file with: B4X: java -jar /home/ec2-user/HelloWorld/HelloWorld.jar This produces the following error. Does anybody have an idea what the problem might be? B4X: main._appstart (java line: 55) java.net.SocketException: Permission denied at java.base/sun.nio.ch.Net.bind0(Native Method) at java.base/sun.nio.ch.Net.bind(Net.java:455) at java.base/sun.nio.ch.Net.bind(Net.java:447) at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227) at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:80) at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:340) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:308) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.server.Server.doStart(Server.java:398) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:220) at b4j.example.main._appstart(main.java:55) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109) at anywheresoftware.b4a.BA.raiseEvent(BA.java:96) at b4j.example.main.main(main.java:28) main.main (java line: 28) java.lang.RuntimeException: java.net.SocketException: Permission denied at anywheresoftware.b4a.BA.raiseEvent2(BA.java:138) at anywheresoftware.b4a.BA.raiseEvent(BA.java:96) at b4j.example.main.main(main.java:28) Caused by: java.net.SocketException: Permission denied at java.base/sun.nio.ch.Net.bind0(Native Method) at java.base/sun.nio.ch.Net.bind(Net.java:455) at java.base/sun.nio.ch.Net.bind(Net.java:447) at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:227) at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:80) at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:340) at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:308) at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.server.Server.doStart(Server.java:398) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at anywheresoftware.b4j.object.ServerWrapper.Start(ServerWrapper.java:220) at b4j.example.main._appstart(main.java:55) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109) ... 2 more
JordiCP Expert Licensed User Longtime User Dec 28, 2021 #2 Just guessing, perhaps port 80 is already taken by some other service in your EC2 instance Upvote 0
Xandoca Active Member Licensed User Longtime User Dec 28, 2021 #3 Have you tried to execute the jar from /home/ec2-user/HelloWorld"? Upvote 0
roumei Active Member Licensed User Dec 28, 2021 #4 Just guessing, perhaps port 80 is already taken by some other service in your EC2 instance Click to expand... Thank you. The EC2 instance is completely new. Do you know a way to check this? Have you tried to execute the jar from /home/ec2-user/HelloWorld"? Click to expand... Yes, that gives the same error. Upvote 0
Just guessing, perhaps port 80 is already taken by some other service in your EC2 instance Click to expand... Thank you. The EC2 instance is completely new. Do you know a way to check this? Have you tried to execute the jar from /home/ec2-user/HelloWorld"? Click to expand... Yes, that gives the same error.
Xandoca Active Member Licensed User Longtime User Dec 28, 2021 #5 roumei said: Thank you. The EC2 instance is completely new. Do you know a way to check this? Click to expand... Try to change to a different port like 51042. (remember to change in app first). Upvote 0
roumei said: Thank you. The EC2 instance is completely new. Do you know a way to check this? Click to expand... Try to change to a different port like 51042. (remember to change in app first).
roumei Active Member Licensed User Dec 28, 2021 #6 Thank you! I changed the port as suggested to 51042 in the B4J project and opened all ports for the EC2 for testing purposes. This solved the 'Permission denied' error and the server seems to be running now. I then tried to access the public ip address but that failed with a 404 error. Do you know if I have to specify a folder? (I randomly tried with /HelloWorld, /www, /HelloWorld/www and with/without index.html). Attachments 404.PNG 13.7 KB · Views: 560 Upvote 0
Thank you! I changed the port as suggested to 51042 in the B4J project and opened all ports for the EC2 for testing purposes. This solved the 'Permission denied' error and the server seems to be running now. I then tried to access the public ip address but that failed with a 404 error. Do you know if I have to specify a folder? (I randomly tried with /HelloWorld, /www, /HelloWorld/www and with/without index.html).
Xandoca Active Member Licensed User Longtime User Dec 28, 2021 #7 roumei said: Thank you! I changed the port as suggested to 51042 in the B4J project and opened all ports for the EC2 for testing purposes. This solved the 'Permission denied' error and the server seems to be running now. I then tried to access the public ip address but that failed with a 404 error. Do you know if I have to specify a folder? (I randomly tried with /HelloWorld, /www, /HelloWorld/www and with/without index.html). Click to expand... You should use http://35.156.25.18:51042/hello B4X: srvr.AddHandler("/hello", "HelloPage", False) srvr.AddHandler("/FormExampleHelper", "FormExampleHelper", False) srvr.AddHandler("/FileUpload", "FileUpload", False) Attachments 1640706083712.png 2.7 KB · Views: 610 Upvote 0
roumei said: Thank you! I changed the port as suggested to 51042 in the B4J project and opened all ports for the EC2 for testing purposes. This solved the 'Permission denied' error and the server seems to be running now. I then tried to access the public ip address but that failed with a 404 error. Do you know if I have to specify a folder? (I randomly tried with /HelloWorld, /www, /HelloWorld/www and with/without index.html). Click to expand... You should use http://35.156.25.18:51042/hello B4X: srvr.AddHandler("/hello", "HelloPage", False) srvr.AddHandler("/FormExampleHelper", "FormExampleHelper", False) srvr.AddHandler("/FileUpload", "FileUpload", False)
roumei Active Member Licensed User Dec 28, 2021 #8 Thank you very much, now it seems to work! Upvote 0
roumei Active Member Licensed User Dec 29, 2021 #9 Maybe it's relevant for others trying to set up an AWS EC2 instance: After solving the issues above, it was still not possible to use port 80 and display the default page (index.html) with the public IPv4 address. It seems that the B4J server program running on OpenJDK 11 listened to the IPv6 instead of the IPv4 address. Amazon only supports IPv4 for Elastic IP Addresses. I added the following line in AppStart and now everything is working as expected: B4X: SetSystemProperty("java.net.preferIPv4Stack" , "true") Upvote 0
Maybe it's relevant for others trying to set up an AWS EC2 instance: After solving the issues above, it was still not possible to use port 80 and display the default page (index.html) with the public IPv4 address. It seems that the B4J server program running on OpenJDK 11 listened to the IPv6 instead of the IPv4 address. Amazon only supports IPv4 for Elastic IP Addresses. I added the following line in AppStart and now everything is working as expected: B4X: SetSystemProperty("java.net.preferIPv4Stack" , "true")