E/Socket: Socket connection can not be established

241 views Asked by At

I've been dealing with NPE for a few days. Finally I found where I didn't create instance

private UserModel userInfo = new UserModel();

Now I get error: Socket connection can not be established

So, my app is not working well.

The error message comes from this Java code.

Edit: My console/errors:

E/RecyclerView: No adapter attached; skipping layout
E/Socket: Socket connection can not be established

After adding this .retryOnConnectionFailure(true) two errors remained as seen above. "Socket connection can not be established" is not a regular message and is sent from VehicleBidFragmentPresenterImp.java.

VehicleBidFragmentPresenterImp.java:

public void initSocketHelper(String userId, int auctionId) {
        SocketHelper.getInstance().connect(new SocketHelper.SocketCallBack() {
            @Override
            public void onConnect(Object... args) {
                // send first bid for wake up socket
                sendBid(userId, 4, "1", String.valueOf(auctionId), Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis());
            }

            @Override
            public void onDisConnect(Object... args) {
                Log.d("Socket", "Socket connection close");
            }


            @Override
            public void onError(Object... args) {
                Log.e("Socket", "Socket connection can not be established");
            }


            @Override
            public void onTimeOut(Object... args) {
                if (getView() != null && getView().get() != null)
                    getView().get().bidError("Bağlantınız zaman aşımına uğradı lütfen tekrar bağlanmayı deneyiniz.");
            }


            @Override
            public void onBidError(Object... args) {

                if (args != null && args.length > 0) {
                    try {
                        for (Object data : args) {

                            if (data == null)
                                break;

                            AuctionBidErrorModel bidModel = parseSocketError(data.toString());

                            if (bidModel == null) {
                                getView().get().bidError("Bir hata oluştu daha sonra tekrar deneyiniz.");
                                return;
                            }

                            long id = bidModel.getAuctionId();

                            if (id == auctionId && userId.equals(bidModel.getKey())) {

                                Log.d("Socket", " Error --> " + data.toString());

                                getView().get().bidError(bidModel.getMessage());
                            }
                        }
                    } catch (Exception ignore) {
                        ignore.printStackTrace();
                    }
                }
            }

            @Override
            public void onBidPublish(Object... args) {
                try {
                    if (getView() != null && getView().get() != null) {

                        for (Object data : args) {

                            if (data == null)
                                break;

                            AuctionBidModel bidModel = parseSocket(data.toString());

                            if (bidModel == null) {
                                getView().get().bidError("Bir hata oluştu daha sonra tekrar deneyiniz.");
                                return;
                            }

                            long id = bidModel.getAuctionId();

                            if (id == auctionId && bidModel.getSendType() != 4) {

                                Log.d("Socket", " BidPublish --> " + data.toString());

                                getView().get().bidSend(bidModel);
                            }
                        }

                    }
                } catch (Exception ignore) {
                    ignore.printStackTrace();
                }
            }

            @Override
            public void onClose(Object... args) {

                try {
                    if (args != null)
                        Log.d("SocketHelper", "" + Arrays.toString(args));

                    if (getView() != null && getView().get() != null && args != null) {

                        for (Object data : args) {

                            if (data == null)
                                break;

                            AuctionBidModel bidModel = parseSocket(data.toString());

                            if (bidModel == null) {
                                return;
                            }

                            long id = bidModel.getAuctionId();

                            if (id == auctionId && bidModel.getSendType() != 4) {

                                Log.d("Socket", " Close --> " + data.toString());

                                getView().get().auctionClose();
                            }
                        }

                    }
                } catch (Exception ignore) {
                    ignore.printStackTrace();
                }

            }


            @Override
            public void autoSellCancel(Object... args) {
                try {
                    if (args != null)
                        Log.d("SocketHelper", "" + Arrays.toString(args));

                    if (getView() != null && getView().get() != null && args != null) {

                        for (Object data : args) {

                            if (data == null)
                                break;

                            AuctionBidModel bidModel = parseSocket(data.toString());

                            if (bidModel == null) {
                                return;
                            }

                            long id = bidModel.getAuctionId();

                            if (id == auctionId && bidModel.getSendType() != 4) {

                                Log.d("Socket", " SellCancel --> " + data.toString());

                                getView().get().autoSellCancel();
                            }
                        }

                    }
                } catch (Exception ignore) {
                    ignore.printStackTrace();
                }
            }

            @Override
            public void autoSell(Object... args) {
                try {
                    if (args != null)
                        Log.d("SocketHelper", "" + Arrays.toString(args));

                    if (getView() != null && getView().get() != null && args != null) {

                        for (Object data : args) {

                            if (data == null)
                                break;

                            AuctionBidModel bidModel = parseSocket(data.toString());

                            if (bidModel == null) {
                                return;
                            }

                            long id = bidModel.getAuctionId();

                            if (id == auctionId && bidModel.getSendType() != 4) {

                                Log.d("Socket", " AutoSell --> " + data.toString());

                                getView().get().autoSell();
                            }
                        }

                    }
                } catch (Exception ignore) {
                    ignore.printStackTrace();
                }
            }

            @Override
            public void auctionCounterUpdate(Object... args) {
                try {
                    if (args != null)
                        Log.d("SocketHelper", "" + Arrays.toString(args));

                    if (getView() != null && getView().get() != null && args != null) {

                        for (Object data : args) {

                            if (data == null)
                                break;

                            AuctionBidModel bidModel = parseSocket(data.toString());

                            if (bidModel == null) {
                                return;
                            }

                            long id = bidModel.getAuctionId();

                            if (id == auctionId && bidModel.getSendType() != 4) {

                                Log.d("Socket", " CounterUpdate --> " + data.toString());

                                getView().get().auctionCounterUpdate(bidModel.getNewTotalSeconds());
                            }
                        }

                    }
                } catch (Exception ignore) {
                    ignore.printStackTrace();
                }
            }
        });
    }

What I understand is that the socket somehow gets corrupted after it is installed.

logcat logcat

Can you please help me where to look in logcat?

0

There are 0 answers