Can Android speak to a PC not running Java? - android

Basic question before I get too far into coding. I was told once that in order for the Android Phone to contact a PC server, that server must be written in Java. I find this a little convoluted, but is this the case? Or by using the TCP/IP classes (Socket), can I just read and write binary data over the pipe regardless of who or how the server was written?

TCP/IP is language agnostic, you can create a client/server implementation in any language or platform that supports TCP/IP and communicate with any other TCP/IP connection.
The communication over the protocol is dependent on implementation though so you need to make sure that both client and server implementations understand the communication going over the sockets.

You can write data regardless of what kind of server it is. Whether it's written in Java, PHP, C++, or whatever does not matter. As long as the server knows how to read and write to/from sockets. I've had my Android phone connect to a PHP server today, so either my phone is disobeying the laws of the universe, or...
Also, the same applies for the other way around, it is possible to make clients for other platforms than Android to connect to a server.

I was told once that in order for the Android Phone to contact a PC
server, that server must be written in Java.
That is incorrect. The whole point of TCP/IP was to create a set of rules, a protocol to allow communication across different devices, architectures, operating systems etc.
Any TCP/IP client can communicate with any TCP/IP server period. No exceptions. (provided they implement a common version of the protocol that is)

Related

Sending Data from Android Device to a RaspberryPi

I need some help in terms of choosing a design option for my problem.
I currently managed to implement a RaspberryPi acting as a Server and my local machine to act as the client. This client send JSON-Data to the Server which processes these. Everything is working as expected and I am using TCP-Sockets for the communication.
My problem:
The next step of my project will be, that I will use instead of a PC an Android-Device as client. What I want to achieve is, to send data to the server on the go. What I mean by that is, I do not want to restrict the server to be in a special network neither the client. What can be expected, is that server and client are next to each other, like in the range of a bluetooth connection. My question is, is there a relatively simple way to implement this communication? Is TCP a possible solution for this (even working in mobile networks?) or do I need to use Bluetooth, or is the way to go, to create some kind of network the client/server connects to and communicate here?
Sorry for propably stupid questions, but I am new to all this network stuff.
EDIT:
Since there were no respones, maybe I can do a more precise question. Is there a proper way to scan a network for a device name?
The only way I currently can imagine is to do a bruteforce like check on every IP-Address and resolve the names?
I first tried to let the Pi host an ad-hoc network, but it seems that non-rooted android smartphones do not have the possibility to access ad-hoc networks.
Therefore I made the Pi acting as an access point.
The communication now is very simple realized by a tcp server-client system.

Application for android to display contents from a PC which connected thru wifi

am new to this application developer, first I'll describe the setup of my system. I've one mechanical machine, it connected with a PC via PLC, now I've some data ( decimal numbers) in PC (which is from machine), now
I need to develop an application to display contents (decimal numbers) in the android mobile, which is in PC via WiFi.
And i need to send some command back to PC,
Is it possible with simple application developer with simple coding?
Please help.
You can easily use TCP sockets which are based on IP protocol and will allow you to communicate over any IP network.
For your Server/PC
you can write a simple java tcp server on your PC.
Tutorials:
TCP Server
All About Sockets ... great starting point.
For your Android/Client
you will have to understand the basics on android development and take a look at couple of networking example.
follow these links:
Your First Android App
Android TCP Client Example
Extra :
TCP on Wikipedia no need to read the implimentation details just understand the concept.
If you want to do it only with your PC<->Mobile, you could expose the data-file via a webserver and then let the mobile read that file and expose in a desired manner. This is not a suggested way to do it, as it has several draw backs e.g. limiting exposed data etc.
Assuming that the data you want to expose is not trivial and may contain multiple data sources, Doing it in more-interoperable way will be a bit more work.
Write webservices (REST/SOAP) that expose the data from the server
Write an mobile app that consume the data from the webservice (via a REST client)
Once the app has consumed the data, you can write your
desired ui to display it on the mobile app.

Communication between PC and android phone using wifi

I want to develop a client server application in which server is on PC having wifi and client application in on android phone. I want to make server application using vc++.Net and client application in android. I am newbie in network programming and i am unable to find any clue about this on internet. And I also don't know is it possible that server is made using vc++.net and client is made using android.
Can anybody please direct me how can i move for this. And if possible please provide me some links related to this.
Any help will be appreciated.
Your question is vague and open to a lot of potentially "correct" answers. First of all, the whole wifi v.s. internet part is irrelevant, you just want to communicate from your Android devices to your pc over the network.
The term to look for is sockets. What you do is listen to particular port on the PC (the "server"). You'll have to open up the relevant ports in the firewall.
You then write an android app that communicates with this server, see here for a proper introduction.
There is no problem using a single socket (ip address + port) to connect with multiple devices, as long as your protocol includes a way for each client to identify itself.
...
That said, you can also do all of this at a higher level, running a SOAP/JSON-based client/server scheme (as opposed to writing your own socket-based protocol). See http://wiebe-elsinga.com/blog/?p=405 for an example.
What is the most appropriate choice depends on your exact requirements (performance, deployment) and your level of experience.
Update
You can use jmDNS to achieve this. It's a really helpful library and once you detect the all devices connected to the same wifi you can get their ip and port so you can establish a connection. You can learn more about how to use it here.
Or you can use Android Wi-Fi Direct API which works only for API Level 14+. Here is more information about the API : Wifi-Direct.
how to achieve transfer file between client and server using java socket
Hope it is what you are looking for! : )

(Android, iOS, Windows, Linux) Server Polling Vs Push vs Implement Server

I'm building a multi-OS mirroring system which I would like to implement using a hybrid client-server and p2p communication method (at least that's the best way I have of describing it).
My issue is that at some point I have a central server (appengine, so there are limitations to what I could do because of time and networking capability constraints) that would need to get a message to a host of different devices which are not necessarily running the same OS (Windows, Android, iOS, Linux, etc...).
Android and iOS (or any other mobile platform) are the main problems it looks like I will be having on 2 levels.
1 - They are both limited by battery power (more so than a laptop and desktops shouldn't have that issue at all), so whichever method I use needs to take that into account.
2 - NAT (harder because the user has relatively less control over their firewall than on a network that they are running). My central server will maintain a table of which device has what IP address, but from what I understand if there is NAT or a firewall it won't be able to get to it if the port was not forwarded.
Since I will be writing a specific client for each OS I prefer a solution that is more universal. I have been leaning towards writing an extremely simple HTTP server that sits on each client and takes requests (which appengine is able to send) and treats them as messages that alert the client to perform an action (either with the server or another client). However, I run into the issue of NAT/firewall. For instance if appengine needs to send a message to AndroidDevice1 it would grab its IP address from a table and make a request to it. However this doesn't work if the ports aren't forwarded correctly, and if the user is on 3g/4g the firewall is controlled by the data provider.
Because of this, I started thinking about using Android C2DM but I want a solution I could implement across platforms.
The only other method I could think of is to just have the client poll the server for messages. This has the battery and network consumption issue though.
Would there be any other way to implement this, and if not, which one of the above methods are best in terms of balancing usability, power and data consumption and user input (the less the user has to do to get the client set up (ie port forwarding, etc...) the better)? Please note that I do not intend for this to become a discussion/flame war but a logical presentation of facts.
Thanks in advance!
You can create a persistent TCP connection from the device to the server and then communicate over this open connection. This would be a very simple connection with keepalive packets for the most part.
In theory this would consume some battery through the radio, but in practice I have experienced that the battery is not affected much at all. Key is to keep the communication over this line to a minimum.
If AppEngine does not allow this approach, you can run your own socket server and then communicate between this server and the appengine server using REST. A socket server I have used is Apache MINA and had no issues with scalability.
Another problem you will have with this approach or any other approach is that on iOS (afaik) you cannot keep a tcp socket open when the App goes into background. The only thing to communicate with the iOS device is Apple Push Notification Service
I would prefer rather than having HTTP Connection you should create TCP/IP tunnel and make communication fast and reliable. I have one Chat application which runs perfact for me using TCP/IP. If you use this you will have same logic for multiple platforms. Only thing you need to write is different code for iOS and android.

Tablet(iPad/Android)-Server Communication Protocol

I am going to build a client-server application. The client here is an iPad (or an android-based) tablet. The server is a normal pc. Both the clients and the server are connected to the same network (using WiFi).
Is there a standard way (protocol) for communication between the clients and the server? Are there any framework that can be used to ease this communication?
Thank you
The answer depends by what you define by "server", "client", and "protocol".
Technically, the answer is "yes"; from a practical standpoint the framework you are looking for is called "socket", but regarding the protocol things may get complicated.
A protocol is a syntax structure governing data exchange, i.e., a set of rules you use to request/provide a service (see the IETF website for a list of standard ones).
Sockets, on the other hand, provide you merely a communication channel to bring bytes from one side to another and, on top of which, you are required to implement the protocol.
The good news is that socket are language independent and you can send messages between heterogeneous devices (ipad/android/linux/windows).
Using sockets in java is easy (I am making it very short here)
server side
ServerSocket ss = new ServerSocket(port);
Socket s = ss.accept();
InputStream is = s.getInputStream();
client side
Socket s = new Socket("server.address", port); // same port as above
OutputStream os = s.getOutputStream();
When you write something using os.write() the same bytes will be read by is.read().
What you write on os is the implementation of your protocol.
This topic is covered (for java language) quite well by "Thinking in Enterprise java" by Bruce Eckel, you can access the digital edition for free.
In C/C++/Objective C things are more complicated but you can easily google for tutorials.
Each service defines its own protocol and you should decide if one of the existing will do or you have to define your own, depending on which service you want to implement between the two devices.
If, as in the standard approach, the PC plays the role of server and clients want to retrieve information from it, you might want to consider installing a (very) lightweight web server and access data using HTTPUrlConnection. This is a wrapper for a socket with HTTP protocol management already implemented.
Beware, this is for Java; there is no "standard framework equivalent" for C/C++, I honestly have no idea about objective C.
Please, be also aware of the following:
If client and servers has different architectures binary data exchange may get painful, better define your protocol as a sequence of strings (like SMTP) and encode/decode binaries using base64 or some other method you may want to implement
In order to link the two sockets client has to know the server IP address; if you are running DHCP on your WIFi network then you also need to implement a discovery phase for your service
As a last side note: "client" and "server" are just labels you put on communicating entities depending on who is requesting a service/information (client) and who is providing it (server). Communication is in reality symmetrical and you can use the same structures/functions/code on both endpoints.

Categories

Resources