I am using Java8 and have a **Chat Server** that works perfectly on my *localhost*, but when I deploy it to an OpenShift server, I get the following error:

> 
> java.net.SocketException: Permission denied
> 
> 
> 
> ```
> 2016-09-05 10:36:11,300 INFO  [stdout] (Thread-125) Starting Chat server on localhost:8000 ...
> 2016-09-05 10:36:13,194 ERROR [stderr] (Thread-125) Exception in thread "Thread-125" java.net.SocketException: Permission denied
> 2016-09-05 10:36:13,194 ERROR [stderr] (Thread-125)     at sun.nio.ch.Net.bind0(Native Method)
> 2016-09-05 10:36:13,195 ERROR [stderr] (Thread-125)     at sun.nio.ch.Net.bind(Net.java:433)
> 2016-09-05 10:36:13,195 ERROR [stderr] (Thread-125)     at sun.nio.ch.Net.bind(Net.java:425)
> 2016-09-05 10:36:13,195 ERROR [stderr] (Thread-125)     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
> 2016-09-05 10:36:13,195 ERROR [stderr] (Thread-125)     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
> 2016-09-05 10:36:13,196 ERROR [stderr] (Thread-125)     at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125)
> 2016-09-05 10:36:13,196 ERROR [stderr] (Thread-125)     at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:476)
> 2016-09-05 10:36:13,196 ERROR [stderr] (Thread-125)     at io.netty.channel.DefaultChannelPipeline$HeadHandler.bind(DefaultChannelPipeline.java:1000)
> 2016-09-05 10:36:13,196 ERROR [stderr] (Thread-125)     at io.netty.channel.DefaultChannelHandlerContext.invokeBind(DefaultChannelHandlerContext.java:463)
> 2016-09-05 10:36:13,197 ERROR [stderr] (Thread-125)     at io.netty.channel.DefaultChannelHandlerContext.bind(DefaultChannelHandlerContext.java:448)
> 2016-09-05 10:36:13,197 ERROR [stderr] (Thread-125)     at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:842)
> 2016-09-05 10:36:13,197 ERROR [stderr] (Thread-125)     at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:195)
> 2016-09-05 10:36:13,197 ERROR [stderr] (Thread-125)     at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:338)
> 2016-09-05 10:36:13,198 ERROR [stderr] (Thread-125)     at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:370)
> 2016-09-05 10:36:13,198 ERROR [stderr] (Thread-125)     at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
> 2016-09-05 10:36:13,198 ERROR [stderr] (Thread-125)     at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
> 2016-09-05 10:36:13,198 ERROR [stderr] (Thread-125)     at java.lang.Thread.run(Thread.java:745)
> 
> ```
> 
> 

I have looked at the OpenShift web sockets guide [here](https://blog.openshift.com/paas-websockets/), which says port 8000 should be used. But I still get the error.

On Openshift I am running my **chat server** on a *WildFly Application Server 10* cartridge.

Any advise appreciated.

Here is my code:

**WebAppInitializer.java**

```
    try {
        new Thread() {
            public void run() {
                com.jobs.spring.chat.Server chatServer = new com.jobs.spring.chat.Server();
                chatServer.startServer();
            }
        }.start();
    } catch (Exception e) {
        e.printStackTrace();
    }

```

**Server.java**

```
import java.net.Socket;

import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.listener.ConnectListener;
import com.corundumstudio.socketio.listener.DataListener;
import com.corundumstudio.socketio.listener.DisconnectListener;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * https://blog.openshift.com/paas-websockets/
 * @author Richard
 *
 */
public class Server {

    //private static final String SERVER = "localhost";
    private static final String SERVER = "jbosswildfly-easyjobs.rhcloud.com";
    private static final Integer PORT = 8000;

    public static void main(String[] args) {
        startServer();
    }

    public static void startServer() {
        Configuration config = new Configuration();
        config.setHostname(SERVER);
        config.setPort(PORT);
        final SocketIOServer server = new SocketIOServer(config);

        server.addConnectListener(new ConnectListener() {
            @Override
            public void onConnect(SocketIOClient client) {
                System.out.println("onConnected");
                client.sendEvent("chat_message:message", new Message("Welcome to the chat!"));
            }
        });

        server.addDisconnectListener(new DisconnectListener() {
            @Override
            public void onDisconnect(SocketIOClient client) {
                System.out.println("onDisconnected");
            }
        });

        server.addEventListener("chat_message:send", String.class, new DataListener<String>() {
            @Override
            public void onData(SocketIOClient client, String data, AckRequest ackSender) throws Exception {
                Message message = null;
                try {
                    message = new ObjectMapper().readValue(data.toString(), Message.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                message.setDate(System.currentTimeMillis());
                server.getBroadcastOperations().sendEvent("chat_message:message", message);
            }
        });

        System.out.println("Starting Chat server on " + SERVER + ":" + PORT+" ...");
        server.start();
        System.out.println("Chat server started");
        System.out.println("Chat server Environment Info: " + System.getenv());
        try {
            Socket socket = new Socket(SERVER, PORT);
            printSocketInformation(socket);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Prints debug output (to stdout) for the given Java Socket.
     */
    public static void printSocketInformation(Socket socket) {
        try {
            System.out.format("Port:                 %s\n", socket.getPort());
            System.out.format("Canonical Host Name:  %s\n", socket.getInetAddress().getCanonicalHostName());
            System.out.format("Host Address:         %s\n\n", socket.getInetAddress().getHostAddress());
            System.out.format("Local Address:        %s\n", socket.getLocalAddress());
            System.out.format("Local Port:           %s\n", socket.getLocalPort());
            System.out.format("Local Socket Address: %s\n\n", socket.getLocalSocketAddress());
            System.out.format("Receive Buffer Size:  %s\n", socket.getReceiveBufferSize());
            System.out.format("Send Buffer Size:     %s\n\n", socket.getSendBufferSize());
            System.out.format("Keep-Alive:           %s\n", socket.getKeepAlive());
            System.out.format("SO Timeout:           %s\n", socket.getSoTimeout());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

```

In [this link](https://developers.openshift.com/managing-your-applications/port-binding-routing.html) OpenShift talk about port binding and proxies. I don't really understand all of it. It looks like I should use port 8000 (which I am), but I am not clear what hostname I should use. I am using my application url name (jbosswildfly-easyjobs.rhcloud.com). Is that correct?

If I change the address to, `http://jbosswildfly-easyjobs.rhcloud.com` (i.e. prefix `http://`) I get the following error:

> 
> java.net.SocketException: Unresolved address
> 
> 
> 

[![enter image description here](https://i.stack.imgur.com/F7FWN.png)](https://i.stack.imgur.com/F7FWN.png)