一段时间后聊天会自动断开连接(Android)

时间:2015-09-22 04:45:15

标签: java android session chat

以下代码用于连接会话和发送或接收消息。在logcat中,最后一个表达式是注册和取消注册。

public void run() {
    while (true) {
        synchronized (sessions) {
            for (final OmegleSession session : sessions) {
                // In case anybody tries to run blocking operations ._.
                service.execute(new Runnable() {
                    public void run() {
                        session.checkEvents();
                    }
                });
            }
        }
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            // uh
        }
    }
}

在控制台中获取此错误不超过此:

[2015-09-22 11:38:12 - ddms] null
java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:200)
at com.android.ddmlib.JdwpPacket.movePacket(JdwpPacket.java:235)
at com.android.ddmlib.Debugger.sendAndConsume(Debugger.java:347)
at com.android.ddmlib.Client.forwardPacketToDebugger(Client.java:698)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:344)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)

如果我在每个部分都没有使用runnable,那么我正在使用整个过程,我没有得到任何回复:

public void chatWaiting(OmegleSession session) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mTxtStatus.setText("Connecting...");
                    }
                });
            }
            @Override
            public void chatConnected(OmegleSession session) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mTxtStatus.setText("Stranger Connected :)");
                        //  System.out.println("You are now talking to a random stranger!");
                    }
                });
            }
            @Override
            public void strangerStoppedTyping(OmegleSession session) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                mTxtStatus.setText("Stopped typing!");
                        }
                    });
            }
            @Override
            public void strangerTyping(OmegleSession session) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                mTxtStatus.setText("");             
                mTxtStatus.setText("typing...");
                    }
                });
            }

0 个答案:

没有答案