delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

WebSocket always lost connection to meteor.com and Heroku #47

Closed isdzulqor closed 8 years ago

isdzulqor commented 8 years ago

I have deployed my Server to meteor.com and it's succeed. This is my site http://booklook-coba.meteor.com/. but when I try to connect it with websocket protocol it's failed. This is my protocol "ws://booklook-coba.meteor.com:443/websocket". The connection always lost. I cannot do CRUD into my database even though it's working in my localhost. Could you tell me more about this? Thank you

ocram commented 8 years ago

Sorry for the late reply!

Please try to remove the port string :443 from the URL :)

Does this work?

isdzulqor commented 8 years ago

still not working

ocram commented 8 years ago

In order to help, we really need more information.

Are you running the app on an emulator or on a real device? For many others, connecting to *.meteor.com seems to be working fine.

isdzulqor commented 8 years ago

I connected with Genymotion. I dont know the exact problem, It's just look like this and cannot connect with my genymotion capture

isdzulqor commented 8 years ago

I have deployed to Heroku too, but I got the same problem. This is my log Activity

01-12 07:21:07.001 2128-2128/com.isdzulqor.booklook I/System.out:   onTextMessage
01-12 07:21:07.001 2128-2128/com.isdzulqor.booklook I/System.out:     payload == {"server_id":"0"}
01-12 07:21:07.386 2128-2285/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: run() : ConnectionLost
01-12 07:21:07.386 2128-2285/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: ended
01-12 07:21:07.424 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: fail connection [code = 3, reason = WebSockets connection lost
01-12 07:21:07.424 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: quit
01-12 07:21:07.425 2128-2286/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketWriter: ended
01-12 07:21:07.425 2128-2128/com.isdzulqor.booklook I/System.out: Meteor
01-12 07:21:07.425 2128-2128/com.isdzulqor.booklook I/System.out:   onClose
01-12 07:21:07.425 2128-2128/com.isdzulqor.booklook I/System.out:     code == 3
01-12 07:21:07.425 2128-2128/com.isdzulqor.booklook I/System.out:     reason == WebSockets connection lost
01-12 07:21:07.425 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: worker threads stopped
01-12 07:21:07.497 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: created
01-12 07:21:07.497 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: WS reader created and started
01-12 07:21:07.498 2128-3081/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: running
01-12 07:21:07.500 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketWriter: created
01-12 07:21:07.500 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: WS writer created and started
01-12 07:21:08.147 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: opening handshake received
01-12 07:21:08.147 2128-2128/com.isdzulqor.booklook I/System.out: Meteor
01-12 07:21:08.147 2128-2128/com.isdzulqor.booklook I/System.out:   onOpen
01-12 07:21:08.148 2128-2128/com.isdzulqor.booklook I/System.out: Meteor
01-12 07:21:08.148 2128-2128/com.isdzulqor.booklook I/System.out:   send
01-12 07:21:08.148 2128-2128/com.isdzulqor.booklook I/System.out:     message == {"msg":"connect","support":["1","pre2","pre1"],"version":"1"}
01-12 07:21:08.148 2128-2128/com.isdzulqor.booklook I/System.out:     dispatching
01-12 07:21:08.148 2128-2128/com.isdzulqor.booklook I/System.out: Meteor
01-12 07:21:08.148 2128-2128/com.isdzulqor.booklook I/System.out:   onTextMessage
01-12 07:21:08.148 2128-2128/com.isdzulqor.booklook I/System.out:     payload == {"server_id":"0"}
01-12 07:21:39.614 2128-2739/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: run() : ConnectionLost
01-12 07:21:39.614 2128-2739/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: ended
01-12 07:21:39.654 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: fail connection [code = 3, reason = WebSockets connection lost
01-12 07:21:39.654 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: quit
01-12 07:21:39.655 2128-2740/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketWriter: ended
01-12 07:21:39.655 2128-2128/com.isdzulqor.booklook I/System.out: Meteor
01-12 07:21:39.655 2128-2128/com.isdzulqor.booklook I/System.out:   onClose
01-12 07:21:39.655 2128-2128/com.isdzulqor.booklook I/System.out:     code == 3
01-12 07:21:39.655 2128-2128/com.isdzulqor.booklook I/System.out:     reason == WebSockets connection lost
01-12 07:21:39.665 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: worker threads stopped
01-12 07:21:39.757 2128-2146/com.isdzulqor.booklook W/EGL_emulation: eglSurfaceAttrib not implemented
01-12 07:21:39.757 2128-2146/com.isdzulqor.booklook W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa088c9a0, error=EGL_SUCCESS
01-12 07:21:39.774 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: created
01-12 07:21:39.774 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: WS reader created and started
01-12 07:21:39.779 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketWriter: created
01-12 07:21:39.779 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: WS writer created and started
01-12 07:21:39.781 2128-3546/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketReader: running
01-12 07:21:40.426 2128-2128/com.isdzulqor.booklook D/de.tavendo.autobahn.WebSocketConnection: opening handshake received
01-12 07:21:40.426 2128-2128/com.isdzulqor.booklook I/System.out: Meteor
01-12 07:21:40.426 2128-2128/com.isdzulqor.booklook I/System.out:   onOpen
01-12 07:21:40.427 2128-2128/com.isdzulqor.booklook I/System.out: Meteor
01-12 07:21:40.427 2128-2128/com.isdzulqor.booklook I/System.out:   send
01-12 07:21:40.427 2128-2128/com.isdzulqor.booklook I/System.out:     message == {"msg":"connect","support":["1","pre2","pre1"],"version":"1"}
01-12 07:21:40.427 2128-2128/com.isdzulqor.booklook I/System.out:     dispatching
01-12 07:21:40.427 2128-2128/com.isdzulqor.booklook I/System.out: Meteor
01-12 07:21:40.427 2128-2128/com.isdzulqor.booklook I/System.out:   onTextMessage
01-12 07:21:40.427 2128-2128/com.isdzulqor.booklook I/System.out:     payload == {"server_id":"0"}

And This is my code for inserting values. I didn't remove insecure package so, I didn't need method for doing CRUD. It's not for production.

 class ProsesSignUp extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... params) {
            // insert data into a collection
            Map<String, Object> signUpValues = new HashMap<String, Object>();

            Date timestamp = new Date();
            SimpleDateFormat formatDate = new SimpleDateFormat("dd MMMM yyyy");
            SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm");

            signUpValues.put("username", userName);
            signUpValues.put("email", email);
            signUpValues.put("password", password);
            signUpValues.put("date", formatDate.format(timestamp));
            signUpValues.put("time", formatTime.format(timestamp));
            mMeteor.insert("users_booklook", signUpValues, new ResultListener() {
                @Override
                public void onSuccess(String s) {
                    Toast.makeText(getApplicationContext(), "Success Sign Up", Toast.LENGTH_SHORT).show();

                    subsRequestSignIn = mMeteor.subscribe("requestSignIn", new Object[]{email, password}, new SubscribeListener() {
                        @Override
                        public void onSuccess() {
                            //Toast.makeText(getApplicationContext(), "Subscribe Success", Toast.LENGTH_SHORT).show();
                        }

                        @Override
                        public void onError(String error, String reason, String details) {
                            Toast.makeText(getApplicationContext(), "Subscribe Error\n"
                                    + error + "\n"
                                    + reason + "\n"
                                    + details
                                    , Toast.LENGTH_SHORT).show();
                        }
                    });

                    //Start service
                    Intent i = new Intent(getApplicationContext(), NotificationService.class);
                    getApplicationContext().startService(i);
                    /////////////////

                }

                @Override
                public void onError(String s, String s1, String s2) {
//                    Toast.makeText(getApplicationContext(), "Error Mas", Toast.LENGTH_SHORT).show();
                }
            });
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            progressDialog.dismiss();
        }
    }

And my Uri Protocol is ws://booklook-alhamdulillah.herokuapp.com/websocket. Please help me! I am stuck at this problem. I use Heroku for free and Mongolab sandbox for my MongoDb Database. Thank you

katopz commented 8 years ago

It's appear wss://ddp--6034-booklook-coba.meteor.com/sockjs/547/3w56y_j5/websocket via console. so for you it should be ssl there (but why url still http btw?)

so can you try wss instead of ws? and did you try change port yet? for me 5000 is working like I did here

443 is for ssl and you should make sure none secure is working before secure it tho. It kinda confuse me that your http is no secure but websocket is secure. Maybe that's why it's not work and I don't think you can mixed it.

read here for more http://www.websocket.org/aboutwebsocket.html

isdzulqor commented 8 years ago

@katopz i have changed my uri to be like this new Meteor(this, "ws://booklook-coba.meteor.com/websocket"); in my Android java. but it's still not working. and I have tried to deploy to Heroku too. but it's not working too. I don't know why. I have set my Mongo uri to my mongolab in Heroku. It's still not working. I am newbie in this case. not have experience before..

katopz commented 8 years ago

@isdzulqor try port yet? btw trying to make on localhost first. on real server is another story.

isdzulqor commented 8 years ago

it's pretty working in my localhost. but when i try to deploy it to meteor.com and Heroku. It makes me crazy. I could not figure out my problem. Honestly this is my first time deploy a website..

katopz commented 8 years ago

@isdzulqor To confirm

right? to prove your android is really working by

if this work. it really mean this is meteor serverside problem. And we will fix that. btw, don't even think you can skip any step I list above.

ocram commented 8 years ago

Can you please test this on a real device instead of on the emulator? I tried connecting to your URL ws://booklook-coba.meteor.com/websocket and it worked without any problems. So it really seems to be your emulator (or your internet connection, or a proxy) that's causing the problems.

Anyway, first make sure that your app is accessible over HTTP by opening the app's domain in your web browser. When using the free hosting on Meteor or Heroku, apps often need to be woken up before you can connect to them.