Open joshterrill opened 8 years ago
Same like @joshterrill it doesn't work for me too. Never trigger connect but it triggers disconnect. Not sure how to fix it.
But iOS Socket.io is working on my server, only Android is not working. I suspect, it is the server side setting issue for android. Because, when I point this demo to my server. It didn't trigger connect.
I don't know if it's the cause but it looks the version of library is old.
mSocket = IO.socket("http://chatserver:3000"); Log.e("CONNECTED", "SUCCESS");
It doesn't mean the connection is successfully established even if a socket is created.
You have to listen EVENT_CONNECT
event.
Let me know if there are some errors(use EVENT_ERROR
and EVENT_CONNECT_ERROR
events) or logs.
It may not work running from an emulator... make sure you can access the internet first.
Are you running the server on a localhost?
Oh... I have been able to resolve the issue. It was my firewalld (centos). All I did was enable the port I was using. Sent from my BlackBerry 10 smartphone. From: Austin LazarusSent: Tuesday, January 10, 2017 20:55To: nkzawa/socket.io-android-chatReply To: nkzawa/socket.io-android-chatCc: afolabiolayinka; CommentSubject: Re: [nkzawa/socket.io-android-chat] Problem with connecting to NodeJS server (#36)Are you running the server on a localhost?
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/nkzawa/socket.io-android-chat","title":"nkzawa/socket.io-android-chat","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/nkzawa/socket.io-android-chat"}},"updates":{"snippets":[{"icon":"PERSON","message":"@Lazarus118 in #36: Are you running the server on a localhost? "}],"action":{"name":"View Issue","url":"https://github.com/nkzawa/socket.io-android-chat/issues/36#issuecomment-271680285"}}}
you need to give IP address of localhost in android "http://192.168.0.0:3000" instead of "http://chatserver:3000"
from stackoverflow:
In the latest versions of Android, you need to add AndroidManifest.xml "android: usesCleartextTraffic = true" to allow connections with plain text.
Example:
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true">
It is not working for android 10, 11 if i use normal socket.io that is working fine then what is problem in @nkzawa your api it is working in api 23
For my NodeJS server code, I'm using the chat server code that is linked to in the socket io android tutorial.
I'm following the tutorial above to a tee in my android project.
build.gradle
:AndroidManifest.xml
:MainActivity.java
:When I compile this, no matter what I put as the URL for
IO.socket(<url>)
, it always logs out that it connected. When I load the app, it's supposed to emitmessage
and send"message"
, but I never get it on the server. I never even get a "user connected" log in my server log, which I have setup to log out anytime a something connects to it.Just to test to make sure my server code isn't faulty, I created a client project in NodeJS:
client.js
:And it and the server both log out 'connected' when I run it. So something is wrong with the java code.... I can't figure it out.