日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android与web服务器建立连接失败,Android websocket连接失败

發布時間:2024/7/23 Android 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android与web服务器建立连接失败,Android websocket连接失败 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在開發一個簡單的應用程序,它只是應該連接到websocket服務器并發送簡單的文本消息。我使用nv-websocket-client作為websocket的庫。我似乎無法連接到服務器。我使用wireshark來確定設備沒有收到數據,也沒有數據通過我使用過的任何端口進入,所以我留下了應用程序出現問題的事實。Android websocket連接失敗

public class MainActivity extends AppCompatActivity{

private static final String SERVER = "ws://192.168.2.177:80";

private static final int TIMEOUT = 5000;

WebSocketFactory factory = new WebSocketFactory();

WebSocket ws;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

public void connectWebsocket(View view) throws IOException{

ws = factory.createSocket(SERVER);

try{ws.connect();}

catch (OpeningHandshakeException e){

Log.d("OpeningHandshake", "Hello");

}

catch (WebSocketException e1){

Log.d("WebsocketException",e1.getError().toString());

}

}

public void sendMessage(View view){

ws.sendText("Sending Message...");

}

}

這是我的主要活動。 這是我的布局。

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:orientation="vertical"

tools:context="com.company.websockettest.MainActivity">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Socket Test" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Press to connect"

android:onClick="connectWebsocket"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Press To send"

android:onClick="sendMessage"/>

我得到一個SOCKET_CONNECT_ERROR。而圖書館的文件似乎并沒有給我太多的錯誤本身。感謝任何幫助,我可以得到。

+0

從服務器中刪除ws://。 –

+0

我試過了。我也收到如下錯誤。 “引起:java.lang.IllegalArgumentException:索引0處的方案中的非法字符:192.168.2.177:8000” –

總結

以上是生活随笔為你收集整理的android与web服务器建立连接失败,Android websocket连接失败的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。