EventBus is a library of Greenbot . This is very simple for all users how to implement and its basic use. Here I will also share examples for better understanding. What is EventBus? EventBus is subscribed/publish event bus to communication between components with limited lines of code, in short, its bus for events transfers the data between one activity(class) to another to reflect the changes based on our needs. That makes the data exchange between components like Activity, Fragment, Services, and any kind of backgrounds threads pretty easy. EventBus can handle the threading for us: events can be posted in threads different from the posting thread. Common use can be dealing with UI changes. In Android, UI changes must be done in the Main(UI) thread. In other words, networking or more time-consuming task cannot be handled in the Main thread, for that we must use AsyncTask or Handler to make it more smooth. Now we have one more options use EventBus to change the UI po...
I hope this will help you for how to start communication between Socket Server (Desktop Chat Server Application) and Mobile Application (Android Socket Client).
This application simply look like as chat application. You can add your idea and innovation to make very useful application.
Follow below steps to run application:
- Use custom port and define same port in both application (i.e. Port No: 5657 )
- Define computer IP Address in Android Client Application. (i.e. 192.168.1.x). If you want to run this application in real device, then you can't connect with Desktop Socket Server. For that you need to upload runnable jar file in specific server and then you can use that server IP Address.
- First start Socket Server Application using Start button.
- Now you can start Android application.
- Just Enjoy it !!!
[Socket Server (Desktop Application)]
[Socket Client (Android Application)]
You can download full source from here.
1. SocketAndroidClient (https://github.com/prashantadesara/SocketAndroidClient)
2. SocketServer (https://github.com/prashantadesara/TCPSocketServer)
If you are satisfied then please give your comments.
Thanks for you to spend your valuable time.
Hi Prashant,
ReplyDeleteThank you for this! I am using the Android emulator and I got this to work. However, the code for the SocketServer comes in a .jar executable -- I cannot seem to find the source code. Would you mind sharing?
Thanks
Hi Tarif,
DeleteYa right, I will upload full source code into same directory very soon. Right now I am changing some part in that.
Don't worry you will get source code from same link ASAP.
Thanks for your interest!!!
Thank you so much! I've been trying to get an Android-to-Desktop socket connection working for a whole week for a project I'm working on -- thank you :)
DeleteI committed my code. Now you can access full source code.
DeleteHello Prashant!
ReplyDeleteYour tutorial is quite good. Can you provide me the same code with the modification that when I close the client and reopen the client, while the server is still running then the server and client should resume their chat. its urgent
Hello Aqsa,
DeleteYou need to create that kind of tutorial using my example. You use your logic with when someone logout from Android then save chat history and when its login display those history.
Hey Prashant!
ReplyDeleteI tried it too much but could not succeed. If you say I can provide you my modified code. Please help me if you can. I urgently need this.
Hi Aqsa,
DeleteWhich problem you facing? Can you please elaborate your issue?
I can email u if you provide me your email id. In that way you will be able to see my modification in the code and I hope u can guide me as well.
DeleteHi prashant,
ReplyDeleteThanks for posting the code, really helpful. I have a small problem, I was not able to find the project file in the SocketAndroidClient folder to run the project in eclipse. I tried to create a new project
Can I get the complete project (including the project file).?
I tried to create new project, but it is giving some run-time errors. I appreciate if you post the project file as well. Thank You.
DeleteHi Satya,
DeleteI have attached zip file with .classpath and .project files. Please download it and try it.
projectfiles.zip place under this below path.
https://github.com/prashantadesara/SocketAndroidClient/
Hi Prashanth,
ReplyDeleteHow do I do it for UDP instead of TCP???
Hi Pradeepbabu,
DeleteI would suggest you to please refer below link for UDP connection.
http://www.anddev.org/udp-networking_-_within_the_emulator-t280.html
Thanks for your interest in my blog.
Hi prashant,
ReplyDeletei really really appreciate your work! Well done! Thx
Hi Bhellmann,
DeleteThanks for your interest and comment in my blog.
Thanks,
This comment has been removed by the author.
ReplyDeleteBoth the client and server starts but it does not transfer message from one to another.. is there some kind of connection issue?
ReplyDeleteHi,
DeleteYou got any exception or something any error?
Are you trying into Emulator or Real Device?
Hello Prashant!
ReplyDeleteYour tutorial is very good to understand but Both the client and server starts but it does not transfer message from one to another on real device.I think i need "runnable jar for specific server" as you told.But i have not good knowledge for done it.Can you provide that jar for server and how to use it simply...
Thank you very much
Hi Ashish,
DeleteI already posted this article with full source code of Android as well as Java Desktop Application.
Then also I will give you link here. You can also find at the end of every post.
1. SocketAndroidClient (https://github.com/prashantadesara/SocketAndroidClient)
2. SocketServer (https://github.com/prashantadesara/TCPSocketServer)
Thanks for your interest!!!
I'll do something wrong previously but now it's working fine...
DeleteThank you very much.
I don't have knowledge about desktop app.
can you provide some installable code that runs in background on window machine and if user send text using android client than notification appear on window machine this will help me lot..
sorry for my spell mistake...
ReplyDeleteThanks for your tutorial .. And please help me ,i have some error in android pgm.
ReplyDelete"java.lang.NoSuchFieldError: android.os.AsyncTask.THREAD_POOL_EXECUTOR"
I though that that error is due to low version of Android Version. Which version you are targeting to run the project?
DeletePlease select Android 4.x +.
Hi Prashant..I am a newbie in android..and don't even know how to connect Android client with server. But I feel your project interesting.
ReplyDeleteCan you please say me which technology is used for server connection in Android? PHP or advanced java?..If you post the answer, it will be very helpful for me.
Hi Krupal,
DeleteThanks for you interest on my blog.
In this example I used Java technology on both side server as well as client. I make server as Swing Java Program and Android app as Client.
First you need to start the server using click on START button. (See above Swing program Image.) After that you can run your android app to established the connection between server and your app.
Hi Prashant,
DeleteThanks for your reply.
I am thinking to make a web application with cloud connection and GPS tracking in android. Can you explain which technology should I use to establish server side connection.
Hi Krupal,
DeleteYes its possible and you can manage through JSP + Servlet (Web Application) to start and stop your server.
Finally, Upload your application into Apache Tomcat server and than test it.
Hello Sir... I like Your Work.. But If I want to use this on my mobile phone than ?? this is not working. both devices are on same network.. and can i use with mobile data connection and changing to external ip of computer ?? is that work ??
ReplyDeletecould you tell me how to run the client program in androidstudio
ReplyDeleteSearched a long time to find a tutorial which provides a solid connection. Your does! 100% stable, no data gets lost! Awesome.
ReplyDeleteThanks so much, bro!
Hi Martin,
DeleteThanks for your interest and such a nice comments.
I am believe in sharing knowledge to everyone. And I am happy to say that some of you guys got the exact code which I posted on my blog.
For this example, I searched a very long time and finally make this example and decided to give you for all person those who are not able run.
Thanks again,
Prashant.
Seriously awesome man :) Really did not find so good tutorial anywhere :)
ReplyDeleteThanks for your comment and reading my blogs.
Deletehow csan i get my ip address
ReplyDeletehow can i run the server
ReplyDeleteYou can manage through JSP + Servlet (Web Application) to start and stop your server.
DeleteFinally, Upload your application into Apache Tomcat server and than test it.
bro i wanna get the text from the client and then open notepad that is if the client sends notepad server should open notepad by comparing it with the string
ReplyDeleteHi Prashant,
ReplyDeleteI want to run this in real device. Can you please tell me step by step what I should do to run this in real device? Is it required another server?
Hi Harshitha,
DeleteYes you can able to run in live server. But for that you need to create runnable jar file and upload into your server. Than use that server's IP in your Android Client Application. (I already given hint on 2nd point on same blog post).
Thanks for your interest.
Thanks,
Prashant.
HI, Using above code how we can do one(server) to many(client) communication.
ReplyDeleteGenerally we aware of that Chat concept. how to achieve using code.
Ex. Sanjay(client) send request and Shyam(client) send a request
Now Server accept both request then Server how to identify which client have requested. so response only them. at smae time
You can handle by Database at Server side to identify by userid and than response to specific users.
Deletecan i do an android to android chat from this app. i dont want to use windows as server. please do share some resources about that.
ReplyDeletesnkumar.nayak@gmail.com
can i live data show on android apps from desktop application
ReplyDeleteIt would be better to use Push Notification, its having many features, You can go with GCM(FCM) for notification, just calling API end point from your Desktop application and all connected device with FCM will get notified by your applied logic.
DeleteDoes it working for multiple android clients and one server ?
ReplyDeleteYes you can.
DeleteHi Prashant I have an query I have an websocket server running as a module and want to establish a websocket / tcp client in android app for that if i only use TCP client source it will work .. I just want to send string from client to server to perform some functionlity. Kindly suggest me
ReplyDeleteYou mean to send String from your Android Device to Server? Can you please clarify in details so I can get better idea what you want to do?
DeleteBurdur
ReplyDeleteGiresun
Sakarya
Artvin
Mardin
SEC2
görüntülü show
ReplyDeleteücretlishow
6EPNN
ankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
NSUSG
https://istanbulolala.biz/
ReplyDeleteEVZVA
karabük evden eve nakliyat
ReplyDeletebartın evden eve nakliyat
maraş evden eve nakliyat
mersin evden eve nakliyat
aksaray evden eve nakliyat
OFBF
71748
ReplyDeleteSamsun Lojistik
Bartın Evden Eve Nakliyat
Malatya Lojistik
Kars Evden Eve Nakliyat
Kırklareli Lojistik
83AA0
ReplyDeleteBtcturk Güvenilir mi
Kilis Evden Eve Nakliyat
Mamak Boya Ustası
Gümüşhane Şehir İçi Nakliyat
Samsun Şehirler Arası Nakliyat
Ankara Lojistik
Karabük Şehirler Arası Nakliyat
Zonguldak Parça Eşya Taşıma
Mardin Lojistik
7C450
ReplyDeleteSivas Evden Eve Nakliyat
Amasya Evden Eve Nakliyat
Sakarya Şehirler Arası Nakliyat
Kırşehir Şehir İçi Nakliyat
Tekirdağ Boya Ustası
Hakkari Şehirler Arası Nakliyat
Eryaman Alkollü Mekanlar
Caw Coin Hangi Borsada
Malatya Evden Eve Nakliyat
44682
ReplyDeleteZonguldak Lojistik
Rize Evden Eve Nakliyat
Mersin Lojistik
Ünye Marangoz
Altındağ Fayans Ustası
Çerkezköy Kombi Servisi
Siirt Evden Eve Nakliyat
AAX Güvenilir mi
Çanakkale Şehir İçi Nakliyat
9444C
ReplyDelete%20 indirim kodu
8F944
ReplyDeletebinance %20 komisyon indirimi
B235B
ReplyDeleteCoin Çıkarma
Bitcoin Nasıl Oynanır
Coin Oynama
Bitcoin Kazma Siteleri
Kripto Para Nasıl Oynanır
Kripto Para Oynama
Coin Nasıl Kazılır
Coin Kazanma Siteleri
Coin Üretme Siteleri
FDF1F
ReplyDeletesightcare
BB605
ReplyDeletebingöl yabancı canlı sohbet
sakarya rastgele sohbet
sinop yabancı sohbet
niğde goruntulu sohbet
eskişehir en iyi ücretsiz sohbet uygulamaları
görüntülü sohbet siteleri ücretsiz
konya canli goruntulu sohbet siteleri
en iyi ücretsiz görüntülü sohbet siteleri
kırıkkale sesli sohbet uygulamaları
97F06
ReplyDeleteeskişehir mobil sohbet
ankara sohbet sitesi
manisa sesli sohbet uygulamaları
antalya ücretsiz sohbet uygulaması
van sesli sohbet siteler
çanakkale chat sohbet
ağrı tamamen ücretsiz sohbet siteleri
adıyaman parasız sohbet
rastgele sohbet
A3674
ReplyDeletesakarya canlı görüntülü sohbet siteleri
bitlis en iyi ücretsiz sohbet siteleri
kırşehir mobil sohbet odaları
kilis sohbet chat
diyarbakır canli goruntulu sohbet siteleri
kırklareli rastgele canlı sohbet
mobil sohbet sitesi
ordu mobil sohbet chat
antalya canlı görüntülü sohbet uygulamaları
BF3B8
ReplyDeleteElazığ Sohbet Sitesi
samsun canlı görüntülü sohbet odaları
malatya canlı görüntülü sohbet uygulamaları
yalova kadınlarla sohbet
sesli sohbet siteleri
Kırklareli Goruntulu Sohbet
Çanakkale Sesli Sohbet Odası
en iyi rastgele görüntülü sohbet
Bolu Canli Sohbet
48A05
ReplyDeleteBitcoin Madenciliği Nasıl Yapılır
Facebook Sayfa Beğeni Satın Al
Milyon Coin Hangi Borsada
Spotify Takipçi Hilesi
Bitcoin Nedir
Ön Satış Coin Nasıl Alınır
Kripto Para Nasıl Üretilir
Hamster Coin Hangi Borsada
Soundcloud Beğeni Satın Al
4D946
ReplyDeleteCoin Para Kazanma
Pepecoin Coin Hangi Borsada
Facebook Beğeni Hilesi
Threads Beğeni Satın Al
Instagram Beğeni Hilesi
Alyattes Coin Hangi Borsada
Coin Nasıl Alınır
Görüntülü Sohbet Parasız
Floki Coin Hangi Borsada
5C5EB
ReplyDeletequickswap
phantom wallet
layerzero
avalaunch
uniswap
debank
defillama
pancakeswap
poocoin
7C8A1
ReplyDeletekaldıraç nasıl yapılır
bitexen
probit
kripto para nasıl alınır
canlı sohbet odaları
paribu
filtre kağıdı
binance ne demek
4g mobil
BF660
ReplyDelete----
----
----
----
----
----
----
----
matadorbet
شركة تسليك مجاري بالخبر DHaeQE5KXl
ReplyDeleteمكافحة الحشرات بالاحساء N0wT6X6JXa
ReplyDeleteشركة مكافحة الحمام بالخبر 5geik0Q2gX
ReplyDeleteشركة مكافحة الصراصير بالدمام W6aOuvKock
ReplyDeleteشركة عزل اسطح بالخفجي lIiaCqAA2y
ReplyDelete