varvet / mobile-websocket-example Goto Github PK
View Code? Open in Web Editor NEWMobile websocket example
Mobile websocket example
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.
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.
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?
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.
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
I was just wondering, Shouldn't we be handling disconnections from the server as well throughout your activity life-cycle? If not, we're gonna end up with tons of connection as the user rotates the screen, am I right?
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).
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.