wifi chat between two or more android devices - java

I want to develop an chat application to chat between two or more android devices using wifi network.The application should be able to send or receive strings from each other. I have an experience of using Bluetooth network between pc and android. Can any give me any suggestion or right direction. Thanks in advance.

You can be able to chat between two android devices in Android Version 4.0.There is an API called 'Wifi P2P'.More information can be had from here:
http://developer.android.com/reference/android/net/wifi/p2p/package-summary.html

If you are thinking about connecting devices that are under the same WiFi AP/router and without setting up any server, then I would suggest you to consider using UDP multicast which has been available since API level 1:
http://developer.android.com/reference/java/net/MulticastSocket.html
UDP does not guarantee data delivery (could be lost), so I would use UDP multicast for device discovery, and open up a TCP connection for data that requires guaranteed delivery. TCP listening port can be advertised via UDP multicast so that everyone can connect with each other over TCP. (There may be 3rd party tool that does this low level stuff for you.)

maybe XMPP will help, google talk uses the same protocol.
The Extensible Messaging and Presence Protocol (XMPP) is an open
technology for real-time communication, which powers a wide range of
applications including instant messaging, presence, multi-party chat,
voice and video calls, collaboration, lightweight middleware, content
syndication, and generalized routing of XML data.
things you need to do:
1. you need a server computer to run XMPP server, there are lots of open source implementations.
2. you need a XMPP client running on your android device, there are also lots of open source implementations running on android platform.

Related

Make an Android App receive data from a non-Android App using Wifi

I am working on an app that will act as a dashboard for an electronic card installed in cars and trucks.
I need the application to be able to receive data from this card, so I can display it in various ways on the app.
We chose Wifi for the communication method. To access the card, my app is able to connect to a Wifi network created by it.
I would like to receive JSON sent by the card every second.
I need help on where to start to make the two devices communicate, and what are the good practices on implementing this kind of communication.
The app basically act as a client, and the card as a server.
I found something about sockets, but it seemed to use two Android devices, a server and a client, so I'm kinda stuck here.
I use Android Studio 2.1.2 with the Android APIs ranging from 19 to latest.
One option is to broadcast with UDP the data within the local network. The moment the android device connects to the wifi network it will be in its local network. So the data can be received at the android end with a multicast receiver(check out http://jgroups.org/ ).
Refer example
It may also use the p2p sharing with TCP and bind the device with static IPs for communication. Create a simple socket receiver at the android end and a service at the device end. Depends on the way you choose it.

GCM vs. Socket in android

In my knowledge, most of android tutorials and examples out there rely on use of GCM for sending data from server to android device; and use php scripts along with post/get methods to send data from device to server.
A friend of mine(someone who doesn't have any knowledge of android programming) simply asked me, why can't we use Socket class in java? In traditional java programming, you use sockets (IP adress + port no.) to achieve functionality similar to GCM (single server multiple clients - using proper techniques you can ensure messages are not lost, just like gcm).
Can this traditional socket approach be implemented in android as well? If so, what are the pros and cons of GCM and Sockets? In which situations would the use of sockets be appropriate?
Whatsapp and lot of other apps, to my knowledge, use GCM. Are there apps which use sockets?
P.S: I'm just a C.S. student; apologies if I've got my concepts wrong somewhere
GCM uses sockets too. However, they are managed by the system and thus can do things a regular app cannot do. Generally, for any type of 'push' notifications, the system needs to have a long-lived socket, and a 'notification' is just some data received on that socket. All of this is not too hard to implement on an always connected machine, such as a desktop or a server, but there are additional challenges on mobile. For example, switching networks (3G<->WiFi), going out of range, maintaining a connection without keeping the device awake all the time (and killing the battery in the process). So yes, you could implement something similar using a service , sockets and your own server, but it's not trivial on mobile.
Check out http://mqtt.org/ for an open-source implementation.

Are there any TCP/IP stack implementations on top of Bluetooth for Java, more specificaly for Android?

What I need to do is pair with a Bluetooth enabled device which hosts some webservices and browse for DNS-SD services.
Then I have to pick one of those discovered services and make some http requests over https or other secure method.
I already did this trough WiFi, but for some reasons there's a need to do the same trough Bluetooth.
I did some research yesterday but I haven't found what I need. I'm not sure how to approach this.
Any input on this is welcomed.
Thanks!
Most implementations of bluetooth implement sockets on top of RFCOMM or L2CAP, but these are not standard sockets.
I've never used it, but I believe that the Bluetooth network encapsulation protocol (BNEP) allows for the use of standard TCP/IP networking over Bluetooth. Android does not implement this and I don't think it is widely supported elsewhere.

wireless connection between mobile device and pc

I would like to establish a connection between a mobile device and computer so they can interact with each other. I should be able to send and receive data at both the ends, just like a chat client. How do I go about it? I just want to know the steps involved. I was thinking about sending the data from the device to a database server and then accessing it through the PC, and doing the same on the mobile device, too. Is this a good idea? What alternatives are there?
Since you're using android, this is pretty easy. One easy option is to code a client and server application for your android device and pc. Or, you could just send data on the UDP connectionless protocol.
I'm assuming you know how to build apps for an android phone. There is no need of an intermediate node (a database server or the like), if the goal here is as small as just sending data back and forth.
Here's a good example of a UDP server/client implementation.
And here's a good one for TCP server/client.
Hope that helps.

Android location aware chat application

I need help with this kind of application.I don't know how will two devices communicate over internet. I think I should create database to store users information, and then create sockets for communication. Is there a better way to do this?
Most mobile networks use some form of NAT, so inbound connections to mobile devices are not possible. You'll need an intermediate server. P2P is possible, but to setup a connection you still need a server.
Don't reinvent the wheel: there is already a lot of servers/libraries/protocols that do chat. Just pick one. Most notable one is XMPP, with open protocol, multiple free OSS server implementations and libraries (including Android).
Additionally you can create your own server app, that does login/authentication and location-aware stuff. Once two users are authenticated and location-paired, you can hand-off the chat part to XMPP server.

Categories