Android Building Group Chat App using Sockets – Part 2

In the 1st part, we have learned how to build the socket server and the web chat app. We also did tested the socket server using the web app.

In this part we are going to build the next important component, i.e. android chat app. The app we are about to create will have two screens. The first screen will prompt the user to enter his/her name. This name is to identify the sender whenever a message is received. The second screen is to list the chat messages and to compose a new message.

So let’s start the app by creating a new android project in Eclipse IDE.

6. Create a new activity named NameActivity.java under project’s main package. In this activity we don’t handle anything complex. We just take the user input from EditText and send it to other activity.

After doing the above changes, if you run the app, you should see the name activity launched as first activity. Below is the output of name activity where user can enter their name and move to next activity.

Before going to implement sockets, I would like to create few resource files first which required to create messages interface.

8. Download this background image and paste it in project’s res ⇒ drawable folder. (If you don’t see drawable folder, create a new one and name it as drawable). This image will be used as background repeat image for the chat conversation.

9. Create 3 new xml files under drawable folder named tile_bg.xml, bg_msg_from.xml and bg_msg_you.xml and add below codes. These drawable xml files are used as background for chat messages.

10. Now under res ⇒ layout folder create two more xml files named list_item_message_left.xml and list_item_message_right.xml. These two layout files are used to align chat messages on left and right in the list view.

14. Create another class named Message.java. This model class defines each chat message where it contains message id, text and a boolean flag (isSelf) to define message owner. Using this boolean flag we’ll align message left or right in the list view.

16. Now under your main package create a class named MessagesListAdapter.java to implement the custom list view adapter class. This class plays a major role in rendering the list by aligning the chat messages left or right.

Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: ravi@androidhive.info

Thanks Ravi for your Reply..,
If you are Planning to do that in future then Please Please let us know…

Thanks in Advance…. 🙂

Shan

What if we want to android to android chat please guide

Venkata Prasad

Thanks Ravi,
From long time, I am looking for this.

jp

I get as far as trying to run the server and get 404.

HTTP Status 404 – /WebMobileGroupChatServer/

type Status report

message /WebMobileGroupChatServer/

description The requested resource is not available.

jp

from stackoverflow, this solved it for me,

Click on Window > Show view > Server OR right click on the server in “Servers” view, select “Properties”.
In the “General” panel, click on the “Switch Location” button.
The “Location: [workspace metadata]” should replace by something else.
Open the Overview screen for the server by double clicking it.
In the Server locations tab , select “Use Tomcat location”.
Save the configurations and restart the Server.

Ray

Excellent work man, Got it all up and running in less than an hour with next to no java / droid experience. If you would like some paid work please get in touch.

In mobile app I’ve tried to edit code in Main.activity and replace URLEncoder.encode(name) with URLEncoder.encode(name, “UTF-8”) , but it doesn’t help me =

Any suggestions how to solve it?(

Arken

We can make it work on desktop? Any suggest?

Kelvin

i am getting the following error

org.apache.http.client.HttpResponseException: Not Found

any clue what the issue would be?

Raja Sekaran

Great Tutorial..but better we need php in server side..Thanks anna..

Brom

so good but I want save all chat history.

Dwi Marstya Wibowo

Dear Ravi, how i can create more chat room ?
Thanks

Juan

Ravi, can you do some tutorials about Fragments? i say, i googled a lot about fragments tutorials(more than, for example, creating fragment tabs, post and show SQLite results to a ListView in one of those fragments, etc), really i need to know how to mannage this type of programming…a lot of people have problems to show things in the fragments and play with it…because now the fragments are better than more activities in one application, so..pleaseee

Levi Costa

+1

Allay Khalil

Hy i have implemented this tutorial its fine and working well on same laptop in two diffrent browser like (Google and firefox)but problem is there when i want to test this app web to mobile or mobile to mobile on same wifi connection because i’p address of android device and laptop are different , how i can test this app web to android mobile or two different device on same wife connection

Riz

u must make one laptop to become server then on the same conecction such as wifi connection then on android code set ip with ip localhost laptop as server.

hi Ravi,
I import the project and followed all steps suggested here. I want communication between two android phones. I connected both of them with the same router. but I’m getting the error as below:
“Error! : java.net.ConnectException: failed to connect to /192.168.x.x(port80): connect failed: ETIMEOUT(connection timeout)”. Is there anything that i’m missing?

Is there any way to make it run only through android app without using desktop versions?

maniteja

Hi,

Thanks for your tutorial.

here (webSocket.onopen ) is not firing when i am running the application.can you help me where i did the mistake.
I am using eclipse j2ee and java version 1.6.

Rajendra

Hi Ravi do you know how we can do android video chat(like this tutorial does text/image chat). What i want to do is the application like facetime. Is it possible do develop that application using android? Could you provide some opensource/sample or point to the right direction. Thankyou

Attaaa

Hi,i follow your tutorial very nicee and thank you…i am new developer i want to make silent apps…i just want to make a button when i click on it my mobile going to silent mode and when i again press it will come in a normal mode..please plzz if u have any code about it..

Aman Gupta

Hey Ravi,

Thanks for amazing tutorial, I have used this trick for using node.js but my application is unable to get onMessage callback when some thing is returned to socket from node. Can you please help me out with this trouble.

Thanks in advance.

Sumit

Hey Ravi,
I think this code works when the MainActivity is in foreground, do you have any idea how to maintain connection persistent through out the app, I am developing a chat application using SignalR android client and facing the above problem, i have defined connection in service class, but the problem is i every time i get the message i need to broadcast them to particular activity or fragment . Any better idea that this. Thanks in advance.

NIMA

hi Ravi

I import the project and followed all steps suggested here. I want
communication between two android phones. I connected both of them with
the same router. but I’m getting the error as below:
“Error! :
java.net.ConnectException: failed to connect to /192.168.x.x(port80):
connect failed: ETIMEOUT(connection timeout)”. Is there anything that
i’m missing?

prashant

dude change the ip accordingly. not the ravi’s one.

کاظم از شیراز

I import the project and followed all steps suggested here. I want
communication between two android phones. I connected both of them with
the same router. but I’m getting the error as below:
“Error! :
java.net.ConnectException: failed to connect to /192.168.x.x(port80):
connect failed: ETIMEOUT(connection timeout)”. Is there anything that
i’m missing?

In Eclipse, go to Project -> Clean. It will generate R file again. Make sure that you don’t have any errors in xml files.

dan li

Chinglish?haha.好不容易遇见中国人呢

smithy14

Hi Ravi, great tutorial and worked perfectly.
It would be great to know how would I go about transferring the server side onto a live server?

Jelqui

Thank you this tutorial is amazing! and easy to understand +100

Duy

how about I want to make an other is not the same Wifi network?

peoce

Thank you very much. the tuition is very awesome. It’s helps my a lot.

kalle

thanks for this great tutorial, but i have a question, i want to run this on my local Ubuntu server and access it with my mobile phone. if i run this programm over my pc it is running but when i start it over the server i get “Error! : org.apache.http.client.HttpResponseException: Not Found” what should i do?

thenoelb

I’m having the same problem.

alex

i have the same problem…. but i guess its the library socket

Omar

i have same problem , what do you mean by the library socket ?
is there is something that the host server doesn’t support comparing to localhost or what ?

Mike

Hello, I see you put your app on the rhcloud.com. Please tell what was the var socket_url value that you set in main.js in server part. Thank you!

Omar

Hello , I am extremely sorry for not sharing the solution that worked for me yet
it was to check that if your host server is supporting socket connection or not you can do this by contacting your web host administration or search in their docs .

i’m having some troubleshoot with this app (i guess its something really simple that i missed), could someone please help me out on skype?
please?

eric

Hi Ravi, Thank you very much for this tutorial

I want to send data to particular user using sockets.

I am working on application were i need to send some data to specific user without much of delay. Actualy I have more then 1000 users who are online out of those I want to select one user and send the data to him only.

I had two solution

1.current implementation=>

So far I am using push notification for this purpose I get the user’s device Id and send notification to him but problem is push notification(sending/receiving) depend on my server and GCM server so it get delayed sometime(I observed sometime it gets delayed by 5 min also).

2.Not implemented=>

Another option is to run thread continuously to check any msg is arrived, if arrived check if whether is meant for same user or not,if he is targeted user then show the data else discard .But here also problem is even if this msg dose not belong to that user one need to check the condition and then discard.

Do you have a solution ?

thanks in advance

Guest

Hi Ravi, Thank you very much for this tutorial.
I want to display the emotion in message. can you give me someways to do. 🙂

Hi Ravi. I’m trying to send pictures using this chat. I’m doing as follows:
Transform the bitmap image in String, create a new flag called photo and send to the server. I managed to send very small pictures, but when I send photos of 5 MB it gives an error saying that the text is too large and can not be sent by parts. Do you have any solution for this?

Hello Ravi, Thanks for this great tutorial, but i have a question, i want to run this on my local server and access it with my mobile phone. if i run this program over my pc it is running but when i start it over the server i get “Error! : org.apache.http.client.HttpResponseException: Not Found” what should i do? Please Help me

Omar

Hello , I have this problem exactly when upload to my hosting also .
did you find any solution ?

Bekarys

Hello Omar, so, did you find any solution?)

Omar

Hello Bekarys ,
I am extremely sorry for not sharing the solution that worked for me yet , yes I found it .
it was to check that if your host server is supporting socket connection or not you can do this by contacting your web host administration or search in their docs .
If it supports socket connection ” my case was using openshifthttps://openshift.redhat.com/app/login?then=%2Fapp%2Fconsole
then search for what port it use
i found this link :

Hey Ravi, i hosted the WebMobileGroupChatServer . but its not connecting to the websocket.

Wander Martinez

Hello, good guide. I did everything work locally but now I would like to upload it to my hosting, example.com. Now that door and I have to put ip? could you explain why I get this error: org.apache.http.client.httpresponseexception: not found.
I loaded the whole folder in my hosting server, but I can not to communicate. I tried to get on the web and funciona everything but not in the mobile app.
help me please

Omar

Hello , I have this problem exactly when upload to my hosting also .
did you find any solution ?

Omar

I am extremely sorry for not sharing the solution that worked for me yet
it was to check that if your host server is supporting socket connection or not you can do this by contacting your web host administration or search in their docs .

2nd i get error in MainActivity.java n MessagesListAdapter.java error as The type MainActivity is already defined and MessagesListAdapter cannot be resolved to a type

Rest all code is error free…

hope u will help me out soon..

thnx…

Omar

Hello all , I am extremely sorry for not sharing the solution that worked for me yet
it was to check that if your host server is supporting socket connection or not you can do this by contacting your web host administration or search in their docs .

I noticed that you’re initializing LayoutInflater in getView() of MessageListAdapter.
I think it will initialize the inflater when getView get called,isn’t?
So my quistion is – “Can we initialize the inflater in the Constructor??”,”Does it cause any problems in future?”

hi, I’ve gotten the app to work and the mobile website to work. Now i would like to use it to where a user doesn’t have to be connected to my network to chat. I’m assuming I have “host the project on a website” I have http://www.clxxxii.com How can i host it to my site. DO i just host the index page or the whole project. I’ve never done this before?

error: Error retrieving parent for item: No resource found that matches the given name
‘Theme.AppCompat.Light’.

2. R value cannot be resolved. I’ve done every possible solution available on the internet, but it is not working. Finally, I used ctrl+shift+O to import required files, but R file isn’t there in the gen folder and also it has further generated lots of new errors.

Install Apache Tomcat server in your hosting or in your VPS. Then Export the web application as WAR file from Eclipse. Open apache tomcat manager console in your browser. Deploy the WAR file. Now you can use your web application from your server link 🙂 I hope it helps.

Ali

how to add group chat in this application
any help ??

Avinash Pandey

i am done with web chat application.Its working correctly,but when i was trying to import your android project with web socket libraryin my workspace,its showing many errors.how to resove it?

Bycoja

First of all, great looking app and very good tutorial. However, although I may very well be wrong, I think there are some potential problems with this implementation. Establishing the websocket connection in the onCreate callback of the activity doesn’t quite strike me as the way to go because we are still executing on the ui thread. Even if the websocket library takes care of this and starts a separate thread, the websocket connection – being tied to the activity – is lost once the activity is killed of by the android system to free resources or the device orientation changes. Also, there is no reason to connect if there is no network available in the first place. I feel like an approach using SyncAdapter would fit quite well here. Have you considered using some of the async components provided by the android framework?

Joseph

if the devices are not connected to the same wifi, how will that be done?

Dima Kovalenko

You will need to provide valid global IP address. 192.168.0.3 is IP address in your local network, so the app only works if device is also connected to local network.

Monica

Please help me m not able to display the messages that are sent and received……I had copy paste the same code….what should i do????

Ajit

i’m getting this error..
Error! : org.apache.http.client.HttpResponseException: Not Found
how to fix it?

JoJo

i could not add the library from github…
Help me how to add library in andriod studio

Hitesh

this application used only wifi connected

Guest

just copy it in the library folder or search how to add external library on android studio

jojo

This project is not compatable for andriod studio?

WaWaToR

Hello everyone. does any one know how to set this up on a webserver? So that it works on the go.
Thank you

It’s working on the emulator,because the emulator can access your “localhost” network,.but “localhost” network is built with Tomact in your PC,not like Server.so you can only access this network in your computer (sorry my bad english)

Hello Sir ..I want to build the same app you did here but want it to work only through wifi connection and not those internet things…Like peer2peer through a wifi network from two or more android devices..can you please help out?

Yaniv

After battling with the code i managed to run it perfectly!!! 🙂
Thanks!!!

The encode is striked out and it says “The method encode(String) from the type URLEncoder is deprecated” and i tried it using with US-ASCII but nothing happened it prompts to use a try and catch block around it. BTW is use new eclipse

amol

1. Go to websocket library and edit its manifest file, remove target sdk= XX, or replace it with your target SDK.
2. Encode method has been deprecated, use encode(“your current string”,”UTF-8″ ), do the necessary changes everywhere required..

New

Is it possible to make chat rooms in it??

Mokib Khan

I am not able to send message and getting following error while adding following code in yours ..

private void sendMessageToServer(String message) {

if (client != null && client.isConnected()) {

client.send(message);

}

else

{

Toast.makeText(this,”client==null or not connected”,Toast.LENGTH_SHORT).show();

}

}

every time when i press send button ..toast “client==null or not connected” prints on screen.

android websockets library library is deprecated can u show with new library

Rishika Kapur

Did you find the solution for android websockets? I also stuck on the same step.

amol

1. Go to websocket library and edit its manifest file, remove target sdk= XX, or replace it with your target SDK.
2. Encode method has been deprecated, use encode(“your current string”,”UTF-8″ ), do the necessary changes everywhere required..

Rishika Kapur

I am building this chat app in Android Studio. I am on the step no. 17. The android websockets library you mentioned is already deprecated, please tell me the alternative to this library and instructions to import and add this library in Android Studio.

For all the people trying to host this application online:
After trying for a while i figured out how to make this work even without being connected to the same Wi-Fi connection.
Find an online hosting company who offers Tomcat v7 and WebSocket services for java application. (I used OpenShift for this purpose)
Compile the application in eclipse and export the .WAR file ( file menu –> Export –> .WAR). Upload the .WAR file to your server using the User’s manual for the specific instructions depending on your hosting company. Then you just have to change the WebSocket addresses in “main.js” and “WsConfig” to match your new online server. For this purpose you will need to verify which port your host company uses to send and receive WebSockets (In my case was port 8000 for normal WebSockets and port 8443 for secured WebSockets). Then write your WebSocket URL as follows:
If, suppose, i have a server at “onlinesocketchat.com” and my .WAR file is named “onlineSocketChat.WAR” the WebSocket URL will be composed as follows:

” ws://onlinesocketchat.com:/onlineSocketChat/chat?name=”
Hope this helps someone who’s been struggling on this as I did!

Cholly Cholly

Hi. I did step by step what you say without any success. I loaded the page fine, but when it comes to the chat room session goes blank. Please help me!

Thanks in advance!

Mike

Hello, I see you put your app on the cloud. Please kindly tell what
was the var socket_url value that you set in main.js in server part.
I’ve tried using localhost, my hosted apps’s domain, other IP’s etc., but nothing works. Only the Name window opens and when I enter name the app can’t connect to socket. Thank you!

Nirav Jain

Successfully hosted online..
Now problem with Websocket library in android studio..
can some one post new MainActivity.java code
from Koush AndroidAsync

Zubi Khan

The app is working fine on localhost..but after deploying .war file on hosting server it’s not working…First screen appears but after that chat window doesn’t show up.. I’m getting this Error ” WebSocket connection to ‘ws://www.example.com/GroupChats/chat?name=Nikki’ failed: Error during WebSocket handshake: Unexpected response code: 404″

GreenJay

Thank you for your example. (Sorry for my english)
l am buiIding in Android Studio, almost everything was done right the first time. I had to tinker with the addition websockets library: as I could not connect the library with the Studio, I just copied the package library to my project. And I changed id for EditText on activity_name.xml from name to name1, because my app is shut.
I have installed on two phone. But I have a bug:
java.net.ConnectException:failed to connect to /192.168.0.109( ip adress phone,which i use as server) (port 8080) after 90000ms:isConnected failed:ECONNREFUSED (Connection refuse)
Can any help ?)

Khoa Hansamu

I also meet same issue

abdullah

Why we are getting socket

abdullah

Why are we getting socket exception?

Shubham

It’s working but is there any code to fetch server IP automatically instead of changing it everytime?

Mohamad Javad A Salehi

Hi, i made this chat step by step ,and project run and come up fine , but finally i have a problem that is : when i enter my name and click on JOIN button the application toast display this expression => Error! : org.apache.http.client.HttpResponseException: Not Found
Can any help me ? thanks!

Axel Olaf

Hello, does anyone knows what if I use mobile data instead of the same wifi network? Thanks¡

Oscar Eduardo Delgado Balleste

anybody knows how to do, a personal chat, but not a chat room, like whatsapp.. or chat in the web page, when the comunication is person to person.

Raj kumar

how do i send and receive image through this library

Chethan Sreenivasa

how to add Theme.AppCompat.Light to the project in eclipse

Raj kumar

you can import the library from D:adt-bundle-windows-x86_64sdkextrasandroidsupportv7appcompat in your project

Monica

I am not able to display the message that are sent and received…………I have copy paste the above code………..what changes i need to do????

Monica

Please reply soon..!!!!!!!!!!!!!!!!!!

The love of your life

You should use all the FileNames he used in the project EXACTLY!!!. And it will work 😀 i struggled with it for 1 week until i realised i dint used the projectname that he used.

monica

i have used the same

Monica

java.net.ConnectException:failed to connect to /192.168.0.109( ip adress phone,which i use as server) (port 8080) after 90000ms:isConnected failed:ECONNREFUSED (Connection refuse)

This is my error Help me

Nikhil

Did you figured it out yet?

Monica

no

Isaac Ayetoro

How can I send attached files like photos, audio and video via this web socket from Mobile to web app and mobile to mobile…?

Shillow

Please how do I add the android websockets library in android studio ???? (the gradle/maven repository was not given at github since android websocktes is now deprecated by androidSync)

I have been following your tutorials ever since I started android app development and trust me, you have really helped me in so many different ways, may God richly bless you.

Please how do I add the android websockets library in android studio
???? (the gradle/maven repository was not given at github since android
websocktes is now deprecated by androidSync)I have been following
your tutorials ever since I started android app development and trust
me, you have really helped me in so many different ways, may God richly
bless you.

rafael rocha

just add the two java class hybiparser and websocketclient and that make it work

Shillow Collins

Thanks very much, could you please send me those 2 java code via shillowc@gmail.com,
Thanks again

rafael rocha

hi sorry about time, you already could make it work?if not please send me a mail to: ralph.8809@gmail.com

Hey Ravi, I have problem following your first post which is to make server socket. Whenever I try to run in server, it says

HTTP Status 404 – /WebMobileGroupChatServer/

type Status report

message /WebMobileGroupChatServer/

description The requested resource is not available.

Apache Tomcat/8.0.26

Please help. Thanks in advance

Olaniyi Ayeni

Here the solution to your erroe @syarifibnumiftahudinaldami:disqus . I also encountered the same error but solved it this way. Your index.html, main.js, style.css and jquery files should be outside the WEB-INF directory inside the WebContent folder. Enjoy.

hamid khaksar

Just Restart the Server , if not work add new Server and Run as the new server .

IF not Working again 😀 download Tomcat 7 and use tomcat 7 😀

eng non

Please help me solving this problem MainActivity Error! : org.apache.http.client.HttpResponseException: Not Found even i do the same as you do in steps

Hi Ravi,Thanks for this tutorial it help lot understand the working of socket but I am facing problem in using AndroidAsync can you please elaborate this tutorial

Raj

Hi Ravi!
First of all i thank you very much.
I have achieve my chatting app in ANDROID as you guide on this tutorial. But now i wants to develop the same logic in IOS (SWIFT) too, is there any IOS version of this library for to achieve this?,
i am facing problem to find the way on this.
Can you guide me please!

Thank You..,

(raj.mscking@gmail.com)

tulasi ram

hi all,
where chatting data will be store(here data base is not used).how to store names, chatting data in MySQL database.can any one tell me what’s the process?

Rahul

BasicNameValuePair has been deprecated, how can i use them??
The webscoket client class use them.

Alex

I would like to use that code on a real Tomcat Server, which address I must put in WsConfig.java and main.js? It’s if it is a normal URL like : subdomain.cloud.com?

Nirav Jain

I have successfully setup on my web host and its working fine from different browser and different wifi and data network. i am at the last step where i am building this app in android studio and MainActivity is showing error WebSocket library is deprecated and replaced by AndroidAsync..
Can anyone modify the Whole code of MainActivity.class and upload it…

you have to download library files for the socket .then after open project folder and create lib folder in root dir. place the library folder inside lib folder.
then after go to studio and change project structure android to project.
then open setting.gradle file and include ‘:lib:’
then open app folder in tree and open app.gradle
inside this under dependancy tag add this line
compile project (‘:lib:’)
after sync proj.
that’s it……

if u got any error in sync the go to library gradle file and comment apply link

Vinod Sonava

hi ravi

which one app is right for the mob to mob chat

Zubi Khan

Everything is working fine…but can we use this code for multiple groups like Whatsapp???

Well i made some changes in this project (i.e. Android Building Group Chat App using Sockets) and now its working for multiple groups also..and then for notification purpose i’ll use GCM as per your suggestion…If time permits i’ll try this new project for sure..Thanx a lot for the suggestion..really appreciated 🙂

HI RAVI
i got a problem…the android_v7 support library is showing error in res->values-v21->styles_base.xml
i google it.. but did not get any solution..
and i changed strings app name like that but when im building the project it’s not reflecting in APK
please give me a solution .. g.jagadeesh.j@gmail.com

Veena

Hi,
I am using android studio for this. but i am not able to add your web socket library(android-websockets-master ) to my project. I tried inserting Compile project statement in build.gradle and include statement in settings.gradle but i am getting below error
com.intellij.openapi.externalSystem.model.ExternalSystemException: Configuration with name ‘default’ not found. Can you please give steps to add it??

Thanks!!!

anil kumar

click right button on project->new->module->select import eclips adt->browse where u have downloaded web master then select that file and click ok.
after finishing the imoprt then u need to go project properties and select dependencies and click + button and select module

Veena

thanks!!

Rajasekhar Reddy

Hi Ravi ,

I followed the steps on using the sockets in my localhost , its working fine . But sometimes it is displaying “org.apache.http.client.HttpResponseException: websocket upgrade failure”, Please guide me in resolving this.

thanks in advance

Badal

Hi , I want to do chat application between android and PC via USB cable . i am able to send data from Android to PC by making ServerSocket in android and Client Socket in PC that is java application. I used adb forward for port forwarding. Everything works fine but ServerSocket becomes null when i close the application. or restart the application. what can i do to keep my Serversocket alive even if the app is closed. I have tried starting ServerSocket when app is already closed and it works properly. problem occurs when i open the application again and it make ServerSocket null.
I even tried adb reverse that is opposite of adb forward which is also not working may be supported for APi 21+.

Hi, I am doing an android application and i am following this tutorial. As i am using android studio, my issue is that i am confused on how to complete part 19 Right Click on project ⇒ Properties ⇒ Android (on left) ⇒ Add (on right, under Library section). Can anyone please aid me on this?

I’m currently building a chat app similar to “whatsapp”. The difference is that I don’t want to implement a group chat function, but some other functionalities instead. Would you recommend using sockets for this project or GCM? Would you mind explaining your answer? Thank you

Veena

Hi,
I have successfully imported your project. But i am getting exception couldn’t connect to Google API and other socket exceptions. Could you please help me with that?

ASK RANASINGHE

import the websocket project as a library. and change the mainactivity code like this,

Would you please suggest a reliable websocket library for android, Should I use firebase for websocket connection since its recommend for android by google. ?

omkar w

so every time we connect to the wifi, we have to change the IP address in the wsconfig.java?
what if i close the socket server and reconnect it? then it has a different IP address. so we build and deploy the app again after changing?
what if i use static IP? would that work?

Krishan Kumar Gupta

I followed the given steps, but the messages are not displayed after clicking on the send button. What could be the possible reason for that?

Piyush Mohnot

Those who are having problem in MainActivity.java, it’s necessary to use target sdk version of 22 or 23 because Websocket is deprecated after sdk version 23.

Nirav Dhanani

@Ravi, Excellent tutorial can you tell me how to possible one to one chatting like whats up using socket io in android.

entire code has to be modify in case of real time chatting application ??

Julius Delfin

can you do this in android studio?

ashish

i already done for studio also.

Akhilesh Rao

in studio you already done it.
so no changes ha we can do it
androidstudio

jai

hello sir,
why i can’t download your coad?

Sumanth Polisetty

How to host these files on a server so that it can be used from anywhere using website url??

Евгений Коммонофф

Please make a
lesson on the Android studio and then the eclipse is not present and
there is no desire to place it, who should be placed and where should
the chat work, can I place it on a web server and work through it?

Gincen

Hi! and thank you for all the tutorials. I want you to make one for an app that can read and send mail that is a mail client app like gmail for android but for our own mail server client in android studio, please. and again thank you

pascal okorie

Can this be done using Android Studio?

Akhilesh Rao

same thing we can do in android studio ha
and by using tomcat server 7

Mantavya Shrivastava

This line is giving error on android studio.
import com.codebutler.android_websockets.WebSocketClient;

Any server works. Have you tried deploying the services on DigitalOcean?

SREEJITH A

Is there any example showing how to use this with AndroidAsync library. The error popsup at
“private WebSocketClient client;” – which class has to be used insted of WebSocketClient.

Sivakumar rajendran

Hi Ravi Tamada,
I have Implemented above code. Everything works fine. Problem i am facing was OnMessage Receive i am posting json to REST API via async task http call. Sometimes it is working. afterwords REST call not working. i am not receiving exception also as well as no response but at that time socket interaction is working fine. I have doubt when socket connected with server not possible to call REST API to same server?