-1

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

为什么会这样……?怎么解决..........?

我的部分代码如下

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>

4

1 回答 1

0

很可能您没有将INTERNET权限放入 manifest.xml

<uses-permission android:name="android.permission.INTERNET" /> 
于 2015-09-25T06:41:23.303 回答