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.
Related
I created a little game and now I am trying to make a multiplayer game out of it. One android phone should host the game and the other phone should be able to connect to this server. My question is how can I tell the Client to which IP he should connect. Is there a way to scan for hosts?
For Android games there is a perfect (and simple) library called kryonet.
It has a method - discoverHost - for scanning local network for devices that are listening for incoming connections.
Also, it contains classes such as:
Client
Server
that makes implementing simple communication protocol (on both UDP and TCP protocols) really easy.
As many people uses this library (including me) - you can find a lot of examples:
The Simplest and Easiest Game Network layer with KRYONET
KryoNet Client and Server Example
Kryonet's itself examples
... and many others. :)
Update 1:
There is also a great library from Google called Nearby Connections API that allows to autodiscover devices in local network and allows to create multiplayer (or multiscreen) games.
Furthermore, Google has created nice (multiplatform) APIs for multiplayer games over the WAN:
Real-time Multiplayer API
Turn-based Multiplayer API.
Sample for Nearby Connections and Real-time Multiplayer APIs you can find here.
You can use Network Service Discovery:
http://developer.android.com/intl/es/training/connect-devices-wirelessly/nsd.html
If I understand you correctly, you want the game host to advertise itself in the reachable network to clients to join.
There are many possibilities around this on different levels of the network protocol stack.
Somethings to look at, that come to my mind:
Rendezvous protocols: https://en.wikipedia.org/wiki/Rendezvous_protocol
Bonjour: https://de.wikipedia.org/wiki/Bonjour_%28Apple%29
A well known central directory server, that keeps track of who is offering and who wants to play (LDAP, DNS, ...)
Word-of-Mouth: Tell your IP to the user and she will broadcast it via voice to other players.
IRC channels or some other means of central communication established outside of your control, like a Twitter account.
You see, there are quite some possibilities. Maybe you want to narrow down you question to your specific needs:
Who is the audience, is it a "LAN-party", other phones somewhere in the mobile space?
How much effort do you want to put into it?
What platforms do you need to support?
I have created database in one application and that application is installed in multiple devices.My requirement is that if i change the value in database of one device then,that changes in database should reflect in another device of same application.I need it without server/third api.
Thanks in advance...
This is precisely when one does need a sever.
Stop and consider what it is that you are asking for. You need a way for a phone to notify all other phones that hold the same application about a change. Phones are not directly addressable to each other via the web, which makes any kind of peer to peer algorithm tricky. SMS texts is the closest form of direct addressing that phones do support, thus it could be used to build a peer to peer protocol, but that would be tricky, unreliable and is unlikely to be beneficial.
A server on the other hand is the standard approach to solving this problem, the server acts as a shared agent that all phones that connect to the web can address easily. Even if the server is just an FTP server on a freebie hosting site.
You need to implement a server functionality in your android application.
What is a server : A server is a running instance of an application (software) capable of accepting requests from the client and giving responses accordingly. Servers can run on any computer including dedicated computers, which individually are also often referred to as "the server".
For further information,I would like to provide this link which will clarify you about communication between two devices Android - communicating between two devices (Use of bluetooth etc.)
I am starter in WebRTC , I want to create simple application with call, but i can not understand what is the server? Is the WebSocket enough? or I need other server?
my scenario is very simple two chrome users A and B, A call B
It depends on your application but you probably want to use server for signaling. The browsers are after establishing session connected peer-to-peer. (it isn't going through your server)
For more detail http://www.html5rocks.com/en/tutorials/webrtc/basics/.
Agree you will probably need a server for signaling. My company OnSIP offers a hosted solution for this, so you would not need to manage servers, but whether you decide to or not - here is an explainer vid on signaling & why you'll need it. Rather than write an explanation here, I'm just going to link it:
https://www.youtube.com/watch?v=-waKd_edBGw
Also, if you intend to run an application that reliably sets up calls 90%+ time, you'll also need media relay (TURN) servers. This is to handle NAT and firewall traversal, which can mess with P2P call setup in real life networking situations as the endpoints have private IP addresses. Media relay servers have a public IP address and literally relay the media stream. These require a lot of bandwidth to run— I don't believe any cloud hosting service will suffice. Again, my company offers this as part of a hosted solution with simple APIs. It is doable to do this all on your own.
Competitive services that handle signaling & media relay & provide developer APIs: EasyRTC & TokBox.
I built an Android application with Google App Engine Server. Now I want to add simple chat to my app. And I have some questions.
My users registered with theirs desired email domains like hotmail.com, yahoo.com and even more esoteric domains, thats mean that I need to create JID for them? if so is Google App engine provide JID creations with my app domain that i can manipulate?
I read that Google App Engine act as XMPP client so I need Xmpp Server that can receive and send XMPP messages. So why do I GAE for? is Openfire is my answer? can I integrate Openfire with GAE?
I Also read that if I want to use XMPP in GAE and Android in need aSmack Api for my client and that it is working on HTTP. So I guess that I'll need to poll the server for messages every couple seconds. Is there a better pattern?
can I integrate Openfire with GAE?
You cannot run Openfire on GAE because GAE works only on HTTP so you won't be able to connect over sockets as Openfire does.
My users registered with theirs desired email domains like hotmail.com, yahoo.com and even more esoteric domains, thats mean that I need to create JID for them? if so is Google App engine provide JID creations with my app domain that i can manipulate?
If I understand your question correctly, you shouldn't have any problems here. As long as you're not a spammer, we don't place any restrictions on what domains you can send to.
I read that Google App Engine act as XMPP client so I need Xmpp Server that can receive and send XMPP messages. So why do I GAE for? is Openfire is my answer? can I integrate Openfire with GAE?
You can send and receive XMPP messages via the xmpp API (this is the python version). This calls into the Google Talk infrastructure. You don't have access to what you'd traditionally call an "XMPP server", but you do have access to basic XMPP functionality.
I don't know a lot about OpenFire, but there is a Trusted Tester program for outbound sockets that you can sign up for. This is what you would need if you desire an external XMPP server.
I Also read that if I want to use XMPP in GAE and Android in need aSmack Api for my client and that it is working on HTTP. So I guess that I'll need to poll the server for messages every couple seconds. Is there a better pattern?
I should prefix this by saying I don't know a whole lot about Android or aSmack, but that won't stop me from taking a stab at answering your question. :-)
I think this depends on your usecase, but I can't think of any situation you'd need to do this off the top of my head. Will the user of your application have their own JID on a server they registered for? If so, I don't see any reason you'd have to connect via HTTP, unless that's all aSmack supports. The main use-case for BOSH/XMPP-over-HTTP is in the browser where you don't really have access to open raw sockets.
If you want to use XMPP as a messaging/notification service the user won't know about, it may be more complex. I should note that you can always set up an XMPP server on Google Compute Engine.
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.