URI serverURI = URI.create("ws://192.168.0.178:8089/android/" + uCode + "/a");
webSocketClient = new WebSocketClient(serverURI) {
@Override
public void onOpen(ServerHandshake handshakedata) {
Looper.prepare();
Toast.makeText(MainActivity.this, "与服务器连接成功", Toast.LENGTH_SHORT).show();
Looper.loop();
}
@Override
public void onMessage(String message) {
Looper.prepare();
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
Looper.loop();
}
@Override
public void onClose(int code, String reason, boolean remote) {
Looper.prepare();
Toast.makeText(MainActivity.this, "与服务器断开连接", Toast.LENGTH_SHORT).show();
Looper.loop();
//跳转到登录界面
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
MainActivity.this.startActivity(intent);
finish();
}
@Override
public void onError(Exception ex) {
Looper.prepare();
Toast.makeText(MainActivity.this, "与服务器连接出现异常,请联系管理员", Toast.LENGTH_SHORT).show();
Looper.loop();
//跳转到登录界面
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
MainActivity.this.startActivity(intent);
finish();
}
};
webSocketClient.connect();
此方法不可用,接收不到数据
此方法不可用,接收不到数据
此方法不可用,接收不到数据
版权声明:本文为weixin_44177447原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。