Cannot connect to RabbitMQ Server from remote machine (Android device)
<p>I've <strong>started RabbitMQ server</strong> on my local machine (Windows 10). Management panel on localhost:5672 is working well. I've <strong>established new user</strong> and wrote example project in java for sending and receiving. It works well with localhost and with my ip address for new established user:</p>

<p><a href="https://i.stack.imgur.com/iK85c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iK85c.png" alt="enter image description here"></a></p>

<p>Unfortunately <strong>i've written the same configuration in my Android project and error</strong> appears:</p>

<pre><code>12-27 00:42:04.601 4393-4393/com.gornik.sendsensors E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: com.gornik.sendsensors, PID: 4393
                                                                  android.os.NetworkOnMainThreadException
                                                                      at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
                                                                      at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:110)
                                                                      at libcore.io.IoBridge.connectErrno(IoBridge.java:154)
                                                                      at libcore.io.IoBridge.connect(IoBridge.java:122)
                                                                      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
                                                                      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:452)
                                                                      at java.net.Socket.connect(Socket.java:884)
                                                                      at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:47)
                                                                      at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:822)
                                                                      at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:778)
                                                                      at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:868)
                                                                      at com.gornik.sendsensors.SendMessages.connectAndPublishMessage(SendMessages.java:27)
                                                                      at com.gornik.sendsensors.MainActivity$1.onClick(MainActivity.java:25)
                                                                      at android.view.View.performClick(View.java:5702)
                                                                      at android.view.View$PerformClick.run(View.java:22541)
                                                                      at android.os.Handler.handleCallback(Handler.java:739)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                      at android.os.Looper.loop(Looper.java:158)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:7229)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
</code></pre>

<p>"connectAndPublishMessage" method:</p>

<pre><code>public static void connectAndPublishMessage(String serverIPAddress) throws IOException{
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("IP ADDRESS");
    factory.setUsername("NEWUSER");
    factory.setPassword("USERPASSWORD");
    factory.setVirtualHost("/");
    factory.setPort(5672);
    try {
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        String message = "Hello world";
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
        Log.d("MESSAGE SENT: ", " [x] Sent '" + message + "'");

        channel.close();
        connection.close();
    }catch(TimeoutException e){
        e.printStackTrace();
    }
}
</code></pre>

<p>Can You figure out <strong>why it is different on my local machine and on Android device</strong>? <strong>How can i connect with my Android device to remote RabbitMQ server?</strong></p>