为什么websocket连接立即关闭......?

时间:2015-09-24 11:00:37

标签: android autobahn autobahnws

当我尝试在android中创建一个websocket连接以使用Autobahn实现wamp时,创建连接并关闭immediatley。

为什么会发生这种情况......?  如何解决..........?

我的部分代码在下面给出

private void start() {
    // TODO Auto-generated method stub
    final String wsuri = "ws://192.168.0.102:8080/ws";
    if (!connection.isConnected()) {
        Log.d("tag", "Not Connected");

    }
    connection.connect(wsuri, new ConnectionHandler() {

        @Override
        public void onOpen() {
            // TODO Auto-generated method stub
            Log.d("tag", "Connected to " + wsuri);
            testPubSub();
        }


        @Override
        public void onClose(int code, String reason) {
            // TODO Auto-generated method stub
            Log.d("tag", "disconnected");


        }

    });
}

protected void testPubSub() {
    // TODO Auto-generated method stub
    connection.subscribe(TOPIC, String.class, new EventHandler() {

        @Override
        public void onEvent(String topicUri, Object event) {
            // TODO Auto-generated method stub
            Log.d("tag", "Event Recieved");
        }
    });
}

很抱歉没有提前发布清单文件。它在下面给出..

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.testwamp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

1 个答案:

答案 0 :(得分:0)

很可能你没有将INTERNET权限放到manifest.xml

<uses-permission android:name="android.permission.INTERNET" />