本文整理汇总了Java中de.tavendo.autobahn.WebSocketException类的典型用法代码示例。如果您正苦于以下问题:Java WebSocketException类的具体用法?Java WebSocketException怎么用?Java WebSocketException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketException类属于de.tavendo.autobahn包,在下文中一共展示了WebSocketException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openConnection
import de.tavendo.autobahn.WebSocketException; //导入依赖的package包/类
/**
* Opens a connection to the server over websocket
*
* @param isReconnect whether this is a re-connect attempt or not
*/
public void openConnection(final boolean isReconnect) {
if (isReconnect) {
if (mConnection.isConnected()) {
connect(mSessionID);
return;
}
}
try {
mConnection.connect(new URI(mServerUri), mWebSocketObserver, mWebSocketOptions);
}
catch (WebSocketException | URISyntaxException e) {
if (mCallback != null) {
mCallback.onException(e);
}
}
}
示例2: Server
import de.tavendo.autobahn.WebSocketException; //导入依赖的package包/类
public Server(WebSocketConnection wsc, Activity act) {
this.wsc = wsc;
this.act = act;
uiInit();
String firstMessage = "Hello~ 点击talk键开始匹配聊天,点击stop结束聊天";
TalkMessage talkMessage = new TalkMessage(3, firstMessage);
chatList = new ArrayList<TalkMessage>();
chatList.add(talkMessage);
chatAdapter = new TalkAdapter(act.getApplicationContext(), chatList);
chatView.setAdapter(chatAdapter);
try {
startServer();
sendListener();
switchListener();
} catch (WebSocketException e) {
e.printStackTrace();
}
}
示例3: rosTopic
import de.tavendo.autobahn.WebSocketException; //导入依赖的package包/类
/**
* This method connects to the server which has an instance of the ROSBridge server running.
* On connection it requests a subscription to the passed topic and creates the topic manager to
* listen to updates from that topic.
* @param new_topic String: Topic selected for debugging/viewing.
*/
private void rosTopic(String new_topic){
mTopicManager = new TopicManager(new_topic.trim() , HOST_ADDRESS, mConnection);
try {
mConnection.connect(HOST_ADDRESS, mTopicManager);
} catch (WebSocketException e) {
e.printStackTrace();
}
if (mLiveCard == null) {
mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_ID);
mRenderer = new TopicRenderer(this, mTopicManager);
mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mRenderer);
//display the options menu when the live card is tapped.
Intent menuIntent = new Intent(this, TopicMenuActivity.class);
menuIntent.putExtra("Destroy", true);
menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
mLiveCard.publish(LiveCard.PublishMode.REVEAL);
}
}
示例4: onStartCommand
import de.tavendo.autobahn.WebSocketException; //导入依赖的package包/类
/**
* Note:
* Services that have already started will receive information through this method.
*
* "startService() delivers a message to an existing running copy of the service,
* via the onStartCommand() method, if the service was already created. If it isn't yet
* created, it will create such a copy (thereby triggering a call to onCreate() first,
* followed by the onStartCommand) if there is no running copy of the service."
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mTimelineManager = TimelineManager.from(this);
try {
mROSMonitor = new ROSMonitorManager(this, mConnection);
mConnection.connect(HOST_ADDRESS,mROSMonitor );
} catch (WebSocketException e) {
e.printStackTrace();
}
return START_STICKY;
}
示例5: pullWebSocket
import de.tavendo.autobahn.WebSocketException; //导入依赖的package包/类
private void pullWebSocket(){
// TODO 使用WebSocket实时推送
SharedPreferences sharedPref = this.getSharedPreferences("appdata",Context.MODE_PRIVATE);
List<BasicNameValuePair> headers = new ArrayList<BasicNameValuePair>();
headers.add(new BasicNameValuePair("Cookie","JSESSIONID="+sharedPref.getString("SessionId", "")));
/*SharedPreferences sharedPref1 = this.getSharedPreferences("userdata",Context.MODE_PRIVATE);
headers.add(new BasicNameValuePair("uid",sharedPref1.getInt("uid", -1)+""));*/
try {
wsc.connect("ws"+declare.getHost_url().substring(4)+"pull.ws", null, new WebSocketConnectionHandler(){
@Override
public void onClose(int code, String reason) {
Log.i(TAG, "onClose reason="+reason);
}
@Override
public void onOpen() {
Log.i(TAG, "后台推送已连接");
}
//接收文本消息
@Override
public void onTextMessage(String payload) {
readingParse(payload);
}
}, new WebSocketOptions(), headers);
} catch (WebSocketException e) {
e.printStackTrace();
}
}
示例6: connect
import de.tavendo.autobahn.WebSocketException; //导入依赖的package包/类
public void connect() {
try {
WebSocketOptions options = new WebSocketOptions();
options.setMaxFramePayloadSize(256000);
application.getConnection().connect(sessionData.getHost(), handler, options);
eventManager.fire(ConnectionEventListener.ConnectionEventType.CONNECTED);
} catch (WebSocketException e) {
e.printStackTrace();
Ln.e("Exception while connecting");
}
}
示例7: onConnect
import de.tavendo.autobahn.WebSocketException; //导入依赖的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");
}
示例8: connectToCar
import de.tavendo.autobahn.WebSocketException; //导入依赖的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();
}
}