I've just learnt and implemented my first Meteor app with simple meteor create hellometeor command, then have used ngrok to make localhost:3000 port live.
Then I have used delight-im/Android-DDP library to connect to the direct ws url as per the following code:
// create a new instance, where mMeteor is a global var.
mMeteor = new Meteor(this, "ws://180a3c0e.ngrok.io", new InMemoryDatabase()); // "ws://180a3c0e.ngrok.io" is the temp. url after tunneling `localhost:3000`
// register the callback that will handle events and receive messages
mMeteor.addCallback(this); // as the activity implements MeteorCallback
// establish the connection
mMeteor.connect();
But every-time I try to run this code, I'm getting the following error, for which I've found no suggestion or straight-forward solution, for a newbie like me in Meteor like platforms during the past 6hrs of googling and reading:
W/System.err: java.lang.Exception: com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.0 502 Bad Gateway
W/System.err: at im.delight.android.ddp.Meteor$1.onError(Meteor.java:195)
W/System.err: at com.neovisionaries.ws.client.ListenerManager.callOnError(ListenerManager.java:432)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.handleError(ConnectThread.java:50)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.run(ConnectThread.java:41)
W/System.err: Caused by: com.neovisionaries.ws.client.OpeningHandshakeException: The status code of the opening handshake response is not '101 Switching Protocols'. The status line is: HTTP/1.0 502 Bad Gateway
W/System.err: at com.neovisionaries.ws.client.HandshakeReader.validateStatusLine(HandshakeReader.java:232)
W/System.err: at com.neovisionaries.ws.client.HandshakeReader.readHandshake(HandshakeReader.java:54)
W/System.err: at com.neovisionaries.ws.client.WebSocket.readHandshake(WebSocket.java:3113)
W/System.err: at com.neovisionaries.ws.client.WebSocket.shakeHands(WebSocket.java:2992)
W/System.err: at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2034)
W/System.err: at com.neovisionaries.ws.client.ConnectThread.run(ConnectThread.java:37)
May be I'm missing a very common thing in the Meteor server-side, as I haven't code a single line in it, other than initiating the project.Please enlighten me in this regard.
TIA.
I should be crucified for not knowing that Meteor has its websocket connection at ws://.../websocket url.
I have just added /websocket at the end of the previous URL and everything is working just as smooth.
Related
I cannot connect to my database thru Compute Engine.
Things I have done so far:
Setup my Compute Engine
Connect my Compute Engine to my Cloud SQL
Install and run Cloud Proxy on my Compute Engine
Included the JDBC Jar file on my libs folder
Created the JDBC Connection string
"jdbc:mysql:///?cloudSqlInstance=&socketFactory=com.google.cloud.sql.mysql.SocketFactory;user=&password=";
Added dependency on my Gradle file
-implementation fileTree(dir: 'libs', include: ['*.jar'])
-implementation 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.1.0'
Here is the stack trace:
W/System.err: java.sql.SQLNonTransientConnectionException: Cannot
connect to MySQL server on localhost:3,306. W/System.err: Make sure
that there is a MySQL server running on the machine/port you are
trying to connect to and that the machine this software is running on
is able to connect to this host/port (i.e. not firewalled). Also make
sure that the server has not been started with the --skip-networking
flag.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
W/System.err: at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:470)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
W/System.err: at
com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197)
at java.sql.DriverManager.getConnection(DriverManager.java:569)
at java.sql.DriverManager.getConnection(DriverManager.java:237)
W/System.err: at
com.dedase.dedaseconstruction.ui.login.LoginActivity$GetPatientID.doInBackground(LoginActivity.java:150)
at com.dedase.dedaseconstruction.ui.login.LoginActivity$GetPatientID.doInBackground(LoginActivity.java:136)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err: at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.mysql.cj.protocol.SocketConnection
com.mysql.cj.protocol.a.NativeProtocol.getSocketConnection()' on a
null object reference
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:980)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:826)
W/System.err: at
com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456)
... 12 more I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread. I/zygote: Do full code
cache collection, code=123KB, data=111KB
After code cache collection, code=117KB, data=78KB
This line localhost:3,306. looks really suspicious. Are you sure you don't have a typo somewhere?
You probably came across this repo, and it's not very accurate. I don't have a java client at hand to test it, but I do use Cloud SQL with a different stack and the point of using Proxy is that your app connects to the DB via it as if the DB itself is running locally. Your connection string should not have anything apart from creds and localhost:3306.
I am trying to connect to mysql using wampp and the following error is thrown how to solve this?
W/System.err: java.io.FileNotFoundException: http://192.168.2.198/login.php
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250)
at com.example.mysqltest.BackgroundWorker.doInBackground(BackgroundWorker.java:46)
at com.example.mysqltest.BackgroundWorker.doInBackground(BackgroundWorker.java:19)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
There are following possibility to occur this issue
maybe your project or file location is not perfect
maybe because of the port number or IP not match time of calling
First, try to run this page in your mobile browser web browser and it will work in mobile browser then it will work in API definitely if not work then you need to change in your config
anybody knows how to connect MYSQL to android studio using MYSQL workbench. I have tried all methods, it shows following error.
com.mysql.jdbc.CommunicationsException: Communications link failure due to
underlying exception:
01-17 16:21:56.845 30367-30442/animaltracking.kevell.com.myapplication
W/System.err: ** BEGIN NESTED EXCEPTION **
01-17 16:21:56.845 30367-30442/animaltracking.kevell.com.myapplication
W/System.err: java.net.SocketException
01-17 16:21:56.845 30367-30442/animaltracking.kevell.com.myapplication
W/System.err: MESSAGE: java.net.ConnectException: Connection refused
You can use the following link to connect third-party database By using rest web services or web services:-
Link:-https://www.youtube.com/watch?v=Ucs-blvF3d8&t=1096s
NOTE:- Use Volley or Volley plus, Retrofit, HttpOk
You should not do this. Instead you should use REST APIs to communicate with database.
https://android.jlelse.eu/consuming-rest-api-using-retrofit-library-in-android-ed47aef01ecb
I'm having trouble with reaching my Google Cloud Endpoints backend from my Android application. I use the following related tools and libraries:
Android Studio 2.3
Gradle plugin - com.google.appengine:gradle-appengine-plugin:1.9.49
App Engine SDK - com.google.appengine:appengine-java-sdk:1.9.49
Endpoints library - com.google.appengine:appengine-endpoints:1.9.49
Endpoints dependencies - com.google.appengine:appengine-endpoints-deps:1.9.49
I've followed the documentation on testing with a physical device against the local development server, which means I've added the line httpAddress = "0.0.0.0" to the build.gradle in the backend module, and I connect to the backend using the following code:
SomeApi.Builder builder = new SomeApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null);
builder.setApplicationName("someapplicationname");
builder.setRootUrl("http://192.168.1.1:8080/_ah/api/");
builder.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer()
{
#Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException
{
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
SomeApi api = builder.build();
I then call a method of the created api using the following line:
api.someMethod("Some random string").execute();
And this is where the problem occurs. This method call triggers the following exception pointing to the same method call (the line above):
W/System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
W/System.err: at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
W/System.err: at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
W/System.err: at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
W/System.err: at se.essvagsystemab.mobiltdispenssystem.licensemanager.simple.fragment.MainFragment$13.doInBackground(MainFragment.java:381)
W/System.err: at se.essvagsystemab.mobiltdispenssystem.licensemanager.simple.fragment.MainFragment$13.doInBackground(MainFragment.java:373)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:304)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err: at java.lang.Thread.run(Thread.java:761)
The strange thing is that the requests doesn't even reach the endpoint. The exception seems to be thrown by the Endpoints library on the client side, because the the server log does not show any signs of error, it contains the log messages printed when starting the server, and that's it.
I have no idea what is causing this, so any help is greatly appreciated!
Turns out that I copied the wrong IP-address from the ipconfig-output, even though I mentioned I'm using the correct IP-address. Hrrm, embarassing...
After trying (what felt like) every possible solution, I once again checked the IP, and it turned out I'd copied the one labeled Default Gateway, which was obviously not as correct as the one labeled IPv4 Address!
So, if you're experiencing the same problem but still you feel like you've done everything correctly, make sure to double check the IP before giving up!
I'm developing a chat application in android. Using XMPP server. PHP server has been migrated to ejabber.
My notification works properly in all scenarios. But in one case I am losing the XMPP messages. In fact I am not getting notifications.
In detail, I am turning off the WiFi or data connection. and after turning off WiFi or data connection any notification sent to me that is not getting. after when I turn ON the WiFi or data connection, I am not able to get the messages which were sent to me.
I have implemented service in background. that makes xmpp connection always live.
I getting this error while i turn OFF the WiFi connection.
java.net.SocketException: sendto failed: EPIPE (Broken pipe)
java.net.SocketException: recvfrom failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:506)
at libcore.io.IoBridge.sendto(IoBridge.java:475)
at java.net.PlainSocketImpl.write(PlainSocketImpl.java:508)
at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:270)
at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:167)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:158)
at java.io.BufferedWriter.flush(BufferedWriter.java:124)
at org.jivesoftware.smack.PacketWriter.writePackets(PacketWriter.java:286)
at org.jivesoftware.smack.PacketWriter.access$12(PacketWriter.java:270)
at org.jivesoftware.smack.PacketWriter$1.run(PacketWriter.java:137)
Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
at libcore.io.Posix.sendtoBytes(Native Method)
at libcore.io.Posix.sendto(Posix.java:146)
at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
at libcore.io.IoBridge.sendto(IoBridge.java:473)
... 9 more
at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:552)
at libcore.io.IoBridge.recvfrom(IoBridge.java:516)
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:489)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:241)
at java.io.InputStreamReader.read(InputStreamReader.java:244)
at java.io.BufferedReader.read(BufferedReader.java:310)
at org.jivesoftware.smack.XMPPConnection$AliveReader.read(XMPPConnection.java:1122)
at org.kxml2.io.KXmlParser.fillBuffer(KXmlParser.java:1496)
at org.kxml2.io.KXmlParser.peekType(KXmlParser.java:979)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:346)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:321)
at org.jivesoftware.smack.PacketReader.access$1(PacketReader.java:216)
at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
Caused by: libcore.io.ErrnoException: recvfrom failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.recvfromBytes(Native Method)
at libcore.io.Posix.recvfrom(Posix.java:131)
at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
at libcore.io.IoBridge.recvfrom(IoBridge.java:513)
... 13 more
So to install mod_archive I need to do this, the typical:
Write following line in cmd. (For cent Os)
Login as root
Create new directory:
mkdir ejabberd_archive_plugin
cd ejabberd_archive_plugin
now get the latest ejabberd modules using following command
yum https://svn.process-one.net/ejabberd-modules
cd ejabberd-modules/mod_archive/trunk
./build.sh
Now go to ebin directory using following cmd and get the list of all *.beam files for ejabberd archive plugins.
root#ns1 [/ejabberd_archive_plugin/ejabberd-modules/mod_archive/trunk/ebin]# ls –l
Using following cmd you will get all ejabberd *.beam files list when ejabberd setup and configure.
root#ns1 [/usr/lib64/ejabberd/ebin]# ls -l
Now copy all *.beam (archive plugins) files to ejabberd ebin directory using following cmd
root#ns1 [/]# cp /ejabberd_archive_plugin/ejabberd-modules/mod_archive/trunk/ebin /usr/lib64/ejabberd/ebin
Now go to following URL and copy all sql table queries and run in phpmyadmin (ejabberd database)
https://svn.process-one.net/ejabberd-modules/mod_archive/trunk/src/mod_archive_odbc_mysql.sql
Now configure ejjaberd.cfg using following cmd
root#ns1 [/etc/ejabberd]# vi ejabberd.cfg
Add the following line into ejabberd.cfg file in modules configuration section
{mod_archive_odbc, [{database_type, "mysql"}, {default_auto_save, true}, {enforce_default_auto_save, true}]},
Now restart the ejabberd service.
root#ns1 [/etc/ejabberd]# sudo service ejabberd restart
You need "Stream Management" XEP-198 enabled connections to achieve this. Georg wrote a good blog entry about that topic: http://op-co.de/blog/posts/XEP-0198/
Basically it allows for stanza acknowledgement and stream resumption, which is exaclty what you want to do in case of e.g a Wifi <-> GSM switch.
I conclude from the stacktrace that you are using aSmack (which is Smack ported to Android). There is a open feature request to implement Stream Management in Smack: SMACK-333. In fact, i've recently started working on the implementation, but can't name an ETA.
You have to create the separate web service for that. so thus why we can handle the history of the sent message. we can manage the offline message.
XEP-198 is the only solution. make plugin for your server and make that easy to manage the remain message that is lose. there may be other solution but AFAIK, this would be the solution.
you can modify archive plugin to save message ids in it.
When user comes online call a web service with last message id received. server can get all the later messages saved on the server. I created it i the same way and working perfectly well.
You should relogin after reconnecting to the internet everytime. But, keep in mind that if you relogin with same resource and same user even it is online then server will throw stream error (replaced by new connection) which will make you offline & you won't receive any message. For this, disconnect yourself properly first before relogin. Try searching on mod Amp module.