Android app need help connecting to a JAVA localhost server - java

I've had a look around and could not find what I'm looking for, so please feel free to redirect me.
I'm writing a card game that uses a Java server that stores the card information. I want to develop an Android app that connects to this server (via TCP/IP is my initial thought) and issues the commands i.e. pick up cards, play cards etc. (as the cards are stored in arraylists within the server app.)
My knowledge of Android is extremely limited and I cant find any good sources that could possibly help me, or explain how android networking works.

You need tcp server socket communication >
http://developer.android.com/reference/java/net/Socket.html

I would recommend to use a REST service and communicate via JSON. You can use for example Robospice in combination with Jackson2 which also brings you async communication and caching out of the box.
https://github.com/stephanenicolas/robospice/wiki/Starter-guide
Socket communication is really old school ;-)

Related

TeamSpeak 3 MusicBot in Java

I want to make a TeamSpeak 3 Musicbot in Java. But I don't find any Protocol from Teamspeak for the Voice transmission. And after searching for a Client API, for Java, I didn't find anything. Only for a ServerQuery but that doesn't help me I think.
I only want the Client to connect to the Server and then plays a Song, though that wouldn't be that hard!
Maybe you Guys can help me?
Teamspeak does not have an official client-api. You can only use the Query-API and create plugins. As the Query-API does not support any voice-communication, that's not the way you should go. The (most) official way of creating a Teamspeak3 MusicBot would be to run a client on your server which has a plugin installed which allows you to play music (more or less a soundboard). Sinusbot is exactly built this way.
Another "unofficial" option would be to make use of unofficial reverses of the teamspeak-protocol and built you own client from these. If you want more information about this, this repository might help you (and look for other projects the creator pushed, they might help you too).
I'm not quite sure if this helps, but have been developing a TeamSpeak 3 music bot using Kotlin, which is compatible with Java as it runs on the JVM (Java Virtual Machine)
The way it works is that it first launches the TeamSpeak client and connects to the desired server and channel, then it starts monitoring the chat log -> the bot can be controlled by entering commands into the chat.
The bot uses the TeamSpeak ClientQuery via Netcat to send messages to the chat.
It is completely client-side so you don't need to be server admin to get it working.
The bot currently supports Spotify, YouTube, and SoundCloud.
You can check it out at https://gitlab.com/Bettehem/ts3-musicbot

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.

Java for android Shared Database over LAN

Hello i've been coding an app (client/server) over my LAN in Visual Studio 2012 using this http://www.codeproject.com/Articles/155282/A-Complete-TCP-Server-Client-Communication-and-RMI#ScsServerside as the base for my communication between the client and the server.
Now i started looking over on android development and eclipse and i was wondering if there was something similar to this framework on java? if not maybe someone could point me out on a way of calling methods over LAN and if possible without using the hole webservice on tomcat thing :p i cant really understand how that is working and since i intend to sell the app i dont know what implications using those components brings.. Whereas this framework i was working on didn't need anything.. it simply runs the application (server) with a service on the ipaddress of the machine on a open port ant that it.. Any help would be gratefull!
Adding some more information to your question would be useful. For example: which kind of call are you accepting on your server? Or, in other terms, what protocol are you using? Just plain old HTTP? RESTful HTTP? FTP? SSH? What?
Anyway, most likely you do not need any third-party framework to create your own Android client. Android and Java already supply you with a HTTP library and a HTTP client that can be used to communicate with a HTTP server. Just browse the docu.
If you have to use a different protocol, most likely you can find a Java client/library that you can use in your project. Java has the largest library of ready-to-use components so it is usually quite easy to find something that can solve your problem.

Chat application - which tech is better to implement chat app in Android

*I have to make an android application which is basically a chat application.*In this chat app the user can interact with single user as well in a group that means Group chat is also there. I am using php as the back end for database . I have never done this type of work earlier so need some suggestions or guidance.
The options i have seen is as follow :
1. Web-services
2. Socket Programming
3. XMPP using the smack api
Now i am confused in them that which is better to implement chat feature in android. Also i didn't get any sample code for that. One of my team member is asking me to use the socket programming but i didn't get any sample app or anything for socket programming in android. I don't know socket programming this time. How we can connect the our phone to the server and then some other device. Hope you get me what i want to Conway you.
So can any one please guide me and show me the right direction to move on. Also if you can provide me any sample code, that can be really helpful. Any help is appreciated
Another option (besides XMPP, which is certainly a valid approach for chat, since it was designed for that) would be using WebSocket. Using WebSocket would open the possiblity of having a pure browser client as well.
For WebSocket on Android, there is AutobahnAndroid, part of the Autobahn family of WebSocket and WAMP implementations.
WAMP is a RPC and PubSub over WebSocket protocol with multiple implementations. There is also a PHP implementation of WebSocket/WAMP: Ratchet.
Disclaimer: I am author of Autobahn/WAMP and work for Tavendo.
For a basic Socket programming tutorial, you can check HERE and HERE.
However, I suggest using XMPP, as I have mentioned HERE, as it is a protocol designed from the ground up to be used for Messaging.

How to implement a real time bidirectional connection with server in android

I have experience developing in android and using REST services, but now I'd like to implement an online game for android. For example a tic-tac-toe for multiplayer, where a user can invite to other to play a game and each one receive the actions of the other in real time.
Using REST for this kind of apps would require constants surveys to the server for updates and its a bad idea.Isn't it?
My question is what are the typical aproaches for this kind of "permanent" connections. I just need some hints about the technologies and protocols in client and server for start searching and read :D
Thanks
You can use sockets directly but for a game like tic-tac-toe, it shouldn't be THAT chatty, using REST would be ok.

Categories