Giter Site home page Giter Site logo

mobile-websocket-example's Introduction

Mobile websocket example

This is example code showing how to use websockets from iOS and Android, in the form of a very simple chat service.

server

A simple websocket server written in Ruby.

browser

Browser client in HTML and JavaScript.

ios

iOS client in Objective-C.

android

Android client in Java.

mobile-websocket-example's People

Contributors

ankor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mobile-websocket-example's Issues

Android client Garbage collector issue

on android when i move to another activity and i finish activity with

   private WebSocketClient mWebSocketClient;

I see in logcat going mad message every 10 ms

GC_FOR_ALLOC freed 512K, 4% free 17338K/17896K, paused 13ms, total 13ms

how to propertly close websocket client and alla associated resources ?
I do

 mWebSocketClient.close(); 

but apparently it is not sufficient

when I set up the client I also use code

SSLContext sslContext = null;
        try {
            sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, null, null); // will use java's default key and trust store which is sufficient unless you deal with self-signed certificates
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }
//
        mWebSocketClient.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(sslContext));

maybe that has to do with it,
also when I tried to investigate what's allocated I found it was about

AllocatedClass javax.net.ssl.SSLEngineResult    
Allocated in org.apache.harmony.xnet.provider.jsse.SSLEngineImpl    unwrap  

any help?

iOS client closes with "Stream end encountered"

When running the iOS client the - webSocket: didCloseWithCode: reason: wasClean: method is immediately executed with the reason being Stream end encountered.

Interacting with the app does nothing afterwards, with no indication that the stream was immediately closed.

Running against iOS SDK 8.1, Xcode Version 6.1 (6A1052d), and SocketRocket (0.3.1-beta2).

wss web socket creation issue

I got - closed connection -1 , draft org.java_websocket.drafts.Draft_17@75599672 refuses handshake , false - then changed the code as below:
Socket creation coode
webClient = new APICWebClient(new URI(getWebSocketUrl(currentApic.IPAddress, port)), new Draft_17());
webClient.connect();

Constructor:
public APICWebClient(URI serverURI, Draft draft) {
super(serverURI, draft);

    SSLContext sslContext = null;
    try {
        sslContext = SSLContext.getDefault();
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    setWebSocketFactory(new DefaultSSLWebSocketClientFactory(sslContext));
    logger.info("Socket object created");
}

Draft_17. I get : closed connection -1 , , true. Any help here. This happens during socket creation.

when ios app is in background webSocket didReceiveMessage method is not getting fired.

I am sending notification from the server using websocketclient chrome extension.

When app is in foreground it works fine and below method is get executed.

- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message { self.messagesTextView.text = [NSString stringWithFormat:@"%@\n%@", self.messagesTextView.text, message]; }

But when app is in background this method is not getting called. when apps comes background to foreground didReceiveMessage function get triggered.

The question is how to make sure didReceiveMessage function get trggred when app is in background?

refuses handshake

Hello,
I am trying to implement android client using this example. I have replaced the "ws://websockethost:8080" with my chat server url, But I am getting
07-24 12:28:06.208: I/Websocket(18294): Closed draft org.java_websocket.drafts.Draft_10@42e49300 refuses handshake
error.

My chat server url is working fine with browser client.
Please help.

Socket is not connected properly

Issue faced in this library :-

When I write the correct port number, no method is called like onOpen(), onMessage() therefore, we cannot determine whether socket connection is established or not.
However, I try to crosscheck by putting the wrong port number, for instance 3005 in place of 3000, then the control falls under onError() method and the above message comes under log.

failed to connect to /112.196.1.218 (port 3005): connect failed: EHOSTUNREACH (No route to host).

I am unable to figure out then, why no method is called when the correct port number is written down.

send method not working

In the Android example, this method is not sending the message

public void sendMessage(View view) {
        EditText editText = (EditText)findViewById(R.id.message);
        mWebSocketClient.send(editText.getText().toString());
        editText.setText("");
    }

I get the following exception:

org.java_websocket.exceptions.WebsocketNotConnectedException

I have checked, and the onOpen method is called, and the onClose is not called.
I also checked that calling the "send" method inside one of the Overrided methods, like onMessage, it works.

Am I doing something wrong? I want to send a message with the click of an item in a listview.

Thanks in advance.

Android 5.0 Lollipop wss stopped working

Hey,

below code worked for Android 4.x.x (also Kitkat), and stopped working on Lollipop

SSLContext sslContext = null;
        try {
            sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, null, null); // will use java's default key and trust store which is sufficient unless you deal with self-signed certificates
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }
        mWebSocketClient.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(sslContext));

mWebSocketClient.connect();

I dont get any error, it just doesnt connect to wss server, onOpen() is never called :/

Please help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.