How to bind DatagramSocket to particular port in O

2019-09-11 07:35发布

问题:

I am running siple java jar service on openshift which tried to connect with DatagramSocket and Getting this Exception:

java.net.BindException: Permission denied
at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:96)
at java.net.DatagramSocket.bind(DatagramSocket.java:397)
at java.net.DatagramSocket.<init>(DatagramSocket.java:251)
at java.net.DatagramSocket.<init>(DatagramSocket.java:304)
at java.net.DatagramSocket.<init>(DatagramSocket.java:276)
at com.gasmps.service.TerminationListener.run(EmailService.java:542)
at java.lang.Thread.run(Thread.java:745)

I know this is port permission problems but i tried with port like 8000,8443,15005,16005 but getting same how could i resolve this? How i can know all open port that can i use in my application.

Edit: My jboss server is already running in the same application and I don't want to create separate application for these jar service bcos I have to run this jar from my application from remote location.

回答1:

Iv looked into this before after having the same issue and discovered the answer on stack-overflow before:

In Openshift, you may only bind to the port that the server allocates for you. Typically that is the value of the environment variable $OPENSHIFT_JBOSS_PORT (it varies between cartridges) and the value differs between gears. Binding to any other port will be reported as an SELinux policy violation and denied. link The port is usually 8080

you can bind your app to 8080 (not to 8000 or 8443), all traffic >received on 8000 and 8443 will be routed by the proxy to your app >listening on 8080.

This worked for me, but let me know how it goes and if it still doesn't work i'll try and help.