Specify a protocol when opening a WebSocket communication

#1

I need to develop a simple android client wich communicate with a websocket server. My client will only send messages to the server.

My server needs the client to specifie a protocol when he wants to connect and I couldn’t do that with Autobahn. (I didn’t find where to put this because it just need the url and port to connect should i just mention it in the wsSubprotocols ? ) My server needs S.th like that (‘ws://192.168.1.1:9000/’, “name of a protocol”);

thanks for help :slight_smile:

0 Likes

#2

Pls see here

http://autobahn.ws/static/reference/android/classde_1_1tavendo_1_1autobahn_1_1_web_socket_connection.html

Here is how you make Autobahn announce "myawesomeprotocol" as subprotocol during initial handshake:

WebSocketOptions options = new WebSocketOptions();
WebSocket sess = new WebSocketConnection();

try {
    sess.connect(wsUri, new String[] {"myawesomeprotocol"}, new WebSocketConnectionHandler() {

       @Override
       public void onOpen() {
       }

       @Override
       public void onClose(int code, String reason) {
       }

    }, options);

} catch (WebSocketException e) {

}

···

Am 06.11.2012 08:37, schrieb nesrine:

I need to develop a simple android client wich communicate with a
websocket server. My client will only send messages to the server.

  My server needs the client to specifie a protocol when he wants to
connect and I couldn't do that with Autobahn. (I didn't find where to
put this because it just need the url and port to connect should i just
mention it in the wsSubprotocols ? ) My server needs S.th like that
('ws://192.168.1.1:9000/', "name of a protocol");

thanks for help :slight_smile:

0 Likes

#3

OK , thanks a lot for the answer.

Just i noticed that

void
connect (String wsUri, String[] wsSubprotocols, WebSocket.ConnectionHandler wsHandler, WebSocketOptions options) throws WebSocketException

is not declared in the interface Websocket .

0 Likes

#4

Ah, ok. Thats a bug. It should be also in the interface .. you may file an issue on GitHub if you like, so it gets fixed ..

Thanks!

Cheers,
Tobias

···

Am 06.11.2012 11:01, schrieb nesrine:

    OK , thanks a lot for the answer.

    Just i noticed that

    void *connect* (String wsUri, String[] wsSubprotocols,
    WebSocket.ConnectionHandler wsHandler, WebSocketOptions
    <http://autobahn.ws/static/reference/android/classde_1_1tavendo_1_1autobahn_1_1_web_socket_options.html> options)
    throws WebSocketException

   is not declared in the interface Websocket .

0 Likes