Receive information through the socket does not work properly - android

I am developing a multiplayer android game, which is sending information through sockets. The game is working fine, but sometimes, it seems that the information that is being sent does not get received. Therefore, I would like a way to ensure that the information goes through. Is this possible?

You have to ensure it yourself,(i'm assuming you are developping the server side as well.) For exemple you can create a server response for each message you send through the socket and try to resend this message as long as the server don't respond correctly.

Related

From server how to call an Android app without any request?

In my app I have functionality like server-side some updates is done. When every updates is happen in server-side I need send those data to app without using push notifications.
Take example of Ola Cabs. Whenever user open the app it will show all cabs information nearby user. At the same time it will send data to the cab drivers telling that a customer needs cab like that. How to implement this functionality with out push notifications?
By using this things we can do that
1) push notifications
2) explicitly calling the server from client with given time (its bad process)
Is there any solution other than these things?
How could client get response without request? Please read OSI Model and TCP/IP protocol. Because server cannot send response without request. So client have to initialize request first and wait for response from server.
If you want to do same thing without GCM then i will suggest you to use socket programming. In that you can be open client port continuously to receive messages (response) without any request initiated by client.
But again, continuously opening socket port, drains device batteries, and this is bad process. In case of GCM it only open port for while when client send request to server and close after response. So I suggest you to use GCM but still you have problem with GCM then use socket programming like chat applications (e.g WhatsApp)

Android streaming text

I'm creating app that has to show live position of some vehicles. Their position is obtained by GPS via Rasberry PI, is sent to my server and there it is converted to Json file. Then on android device I am creating app which converts this file and lets user see vehicle position.
I am downloading it via HTTP protocol, and I think it is good way of solving problem. But my boss is insisting that it could be done by streaming (because, as he says, it is not neceserry to download data from server when vehicle is not moving for about 30 minutes), SO.
What is the way of creating a situation in which android device is not downloading data but waiting for server to send data? Is it even possible?
As far as I know, streaming is constantly sending data to target device, and device is constantly receiving this data.
The only way I can think about is to create server on every android device, send server data to my server (IP, port etc.) and from my server connect to every device and send position only when vehicle is moving - but this is costfull and not proper way I think.
Any ideas or help?
The best way to handle your problem is implementing a GCM and dealing with PUSH NOTIFICATIONS.
If connection is not available at the moment, will be sent when connection will be ok.
If the receiver isn't available at the moment, same things will happen.
It consumes less resources than constantly http calls.
See more information at https://developer.android.com/google/gcm/index.html

push notification for my android chat application

iam developing a chat application and now am on it's push notification part.. And now am in a big confusion.. because in my previous application iam using Google's GCM like, whenever i get a notification from the GCM server i pull data from my server.But in this case i think it's not the right way for a chat because if i try to do like this i have to connect the socket again and user will become in online status.And also am using raw socket for my application.
is there a better way for accomplishing this?
thank you
I am using web socket for push notifications. In my android application (client side) I use Autobahn web socket client. It works fine, but if you want reliable solution then I think you can go for Azure Push Notification Service. But I think you can only send/receive few push notifications using their free service. To scale further you need to pay.
But using web socket you can send as many number of notifications as you want. Further, you can keep the connection always on, so that you don't need to reconnect the socket connection every time. But to ensure the active web socket connection you need implement PingPong. And that PingPong might use some the bandwidth.

Two way communication between android and Server

i want a two communication between server and Android. From Android want to send my current location coordinates to server after each 10 minutes. i can send message or images to server at any time. Similarly from server i want to send data to Android whenever needed.
What should be the architecture of my application.
Communication from Android to server and Server to Android is independent of each other i should not ask it as a two way communication but infact i want communication from both sides to each other any time.
Should i use a Web service of any kind or just network sockets or Something else.
You can use websockets or...
Simply send data from phone to the server using normal request. When you want send something from server to telephone you can use push notifications (C2DM) and if you receive such push message you know that server has data for you and telephone can download it using normal request;-). It depends what data you want to send. Sometimes this approach will be good, sometimes it's better to use websockets, TCP sockets or even XMPP protocol ;-)
You can Use Acknowledge for the same. You need to Implement ACK/NACK Logic in your code. When you are sending Data just wait for ACK for a particular time period. If ACK is not received the you need to send NACK for the same. Here you need to use a session-id ( a kind of id for communication at both side, which can be any random number ).
You can use this Logic at both the side.

Connect two android apps via http REST and EJB3

I'm writing application for android where two devices should communicate between each other via internet. In addition to this task they also communicate with the EJB3 server via REST. So I decided to kill two birds with one stone and use REST+EJB3 for transferring data between two paired android devices.
So the scenario I implemented is something like this:
Both devices connect to the server and acquire session id.
First device sends data to the second device
Server gets the data but does not end the http request, instead it puts into a waiting pool
Second device asks for data
Server transfers the data to the second device and releases waiting connection (and thread) for first device.
If there are no first or second device requests then opponent waits for a timeout on a server side, then sends the request again. We need to wait for the data on the server side to give immediate respose after data is arrived.
So in this schema I see two drawbacks:
- Waiting thread on the server side - they consume server resources and as the result limit server throughput
- If the server thread will not wait for an answer with timeout, then the client should repeat requests on and on and spend a lot of traffic.
What is the best practice solution for such problem?
P.S: Forgot to mention that two devices should exchange data as smoothly and quickly as possible.
You will need to use C2DM
http://android-developers.blogspot.com/2010/05/android-cloud-to-device-messaging.html
When message needs to be sent from A to B - A should connect to server and depending on data kind/amount - server will either push data via C2DM or just tell device B to come back and grab data.
I would store data on server anyway. If push fails - you can retry it. No need to reinvent wheel. Most issues/problems already solved in C2DM

Categories

Resources