TO send the message using mConnection.sendTextMessage(text); it reconnects to server.

#1

I want persistent connection with server. Is’nt it possible with autobahn. Following is the code for android client autobahn

···

public void start() {
// if(mConnection!=null) return mConnection;

  final String wsuri = "ws://172.24.49.127:8080/WebSocketDemo1/serverEndpointDemo1";
  try {
   mConnection.connect(wsuri, new WebSocketHandler() {
  		@Override
  		public void onOpen() {
  			Log.d(TAG, "Status: Connected to " + wsuri);
  			mConnection.sendTextMessage(message);
  			message = "";
  		}
  		@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.");
  		}

   });
  } catch (WebSocketException e) {
  	Log.d(TAG, e.toString());
  }
  //mConnection.sendTextMessage("hi sonu");
  //return mConnection;

}
public void SendTextMessage1(String text) {
if(mConnection.isConnected()){
mConnection.sendTextMessage(text);

  }
  else {
  	Log.d(TAG,"connection Recreated again");
  	message = text;
  	start();
  }

}

0 Likes

#2

I want persistent connection with server. Is'nt it possible with

Well, sure, the WebSocket connection _is_ persistent (otherwise, this whole WebSocket thing would be useless ..).

I'd suggest trying this example:

https://github.com/tavendo/AutobahnAndroid/blob/master/Demo/EchoClient/src/de/tavendo/autobahn/echoclient/EchoClientActivity.java#L158

It has dedidicated buttons for "connect" and "send" ..

Hope this helps ..

/Tobias

···

Am 05.04.2014 09:26, schrieb Nikhil Bhoyar:

autobahn. Following is the code for android client autobahn

    public void start() {
    //if(mConnection!=null) return mConnection;

    final String wsuri =
    "ws://172.24.49.127:8080/WebSocketDemo1/serverEndpointDemo1";
    try {
    mConnection.connect(wsuri, new WebSocketHandler() {
    @Override
    public void onOpen() {
    Log.d(TAG, "Status: Connected to " + wsuri);
    mConnection.sendTextMessage(message);
    message = "";
    }
    @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.");
    }

    });
    } catch (WebSocketException e) {
    Log.d(TAG, e.toString());
    }
    //mConnection.sendTextMessage("hi sonu");
    //return mConnection;
    }
    public void SendTextMessage1(String text) {
    if(mConnection.isConnected()){
    mConnection.sendTextMessage(text);

    }
    else {
    Log.d(TAG,"connection Recreated again");
    message = text;
    start();
    }

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com
<mailto:autobahnws+...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

0 Likes