本文整理汇总了Java中de.tavendo.autobahn.WebSocketHandler类的典型用法代码示例。如果您正苦于以下问题:Java WebSocketHandler类的具体用法?Java WebSocketHandler怎么用?Java WebSocketHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketHandler类属于de.tavendo.autobahn包,在下文中一共展示了WebSocketHandler类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onConnect
import de.tavendo.autobahn.WebSocketHandler; //导入依赖的package包/类
public void onConnect(View v) {
final String wsuri = ((TextView) findViewById(R.id.editTextURL)).getText().toString();
try {
mConnection.connect("ws://" + wsuri + ":1234", new WebSocketHandler() {
@Override
public void onOpen() {
log("Status: Connected to " + wsuri);
mConnection.sendTextMessage("Hello, world!");
buttonPrevious.setEnabled(true);
buttonPlay.setEnabled(true);
buttonNext.setEnabled(true);
}
@Override
public void onTextMessage(String payload) {
log("Got echo: " + payload);
}
@Override
public void onClose(int code, String reason) {
log("Connection lost.");
buttonPrevious.setEnabled(false);
buttonPlay.setEnabled(false);
buttonNext.setEnabled(false);
}
});
} catch (WebSocketException e) {
log(e.toString());
}
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("http://" + wsuri + ":8000");
}
开发者ID:GGreenwood,项目名称:WeeWoo,代码行数:38,代码来源:MainActivity.java
示例2: connectToCar
import de.tavendo.autobahn.WebSocketHandler; //导入依赖的package包/类
private void connectToCar() {
String smartCarIp = carIpText.getText().toString();
final String wsuri = "ws://" + smartCarIp + ":80/index.html?command=true";
// final String wsuri = "ws://" + smartCarIp + ":80";
//
// final String wsuri = "ws://192.168.1.132:9000";
try {
Log.d(TAG, "Trying to websocket connect to " + wsuri);
mConnection.connect(wsuri, new WebSocketHandler() {
@Override
public void onOpen() {
Log.d(TAG, "Status: Connected to " + wsuri);
mConnection.sendTextMessage("Hello, world!");
isConnected = true;
isConnecting = false;
updateUI();
}
@Override
public void onTextMessage(String payload) {
Log.d(TAG, "Got echo: " + payload);
}
@Override
public void onClose(int code, String reason) {
Log.d(TAG, "Connection lost.");
Toast.makeText(getApplicationContext(), "Not connected to car", Toast.LENGTH_LONG).show();
isConnecting = false;
isConnected = false;
updateUI();
}
});
} catch (WebSocketException e) {
Log.d(TAG, e.toString());
isConnecting = false;
isConnected = false;
Toast.makeText(getApplicationContext(), "Could not connect to car", Toast.LENGTH_LONG).show();
updateUI();
}
}
开发者ID:alon24,项目名称:SmartCarAndroid,代码行数:45,代码来源:MainActivity.java
注:本文中的de.tavendo.autobahn.WebSocketHandler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论