I'm trying to make the following work, and wonder if it is possible:
I want to send data from a hardware piece to an android device. Although the hardware only has an Ethernet connection available.
If I were to make an Ethernet connection from the hardware piece to a router, and then communicate from the router to the android device with WiFi, is there any way I could tell the android device, just receive data from the WiFi?
Using IP protocol will allow you to communicate over any IP network.
Easiest way to do that is using TCP sockets that uses Server/Client relation to communicate.
I'm guessing you are using a microcontroller (arduino?) if that is the case there are many IP labraries and examples you can look at.
after writing the server code on the hardware then you can easily use sockets to connect to it from android, here is an example on how to connect android client to TCP server.
TCP Client tutorial
Extra links:
TCP on Wikipedia no need to read the implimentation details just understand the concept.
Java All about Sockets Great overview of socket programming and should get you ready to write effective code on the android side.
LAN wikipedea article about LANs
Related
How can I do these steps in android (Eclipse)? In a simple example. I am beginner.
For transfer data over wi-fi.
Server device opens a socket and listens on it.
Server device broadcasts the local IP and Port it's listening on.
Client devices receive broadcast and initiate a connection.
Transfer data between server and each client or clients and server.
This is very broad and would require a lot of code to show, and therefore I recommend viewing
http://developer.android.com/guide/topics/connectivity/wifip2p.html
WifiP2P is very cool, but can be tricky to setup. If you want to start playing around with wireless communication you may want to look at the BluetoothChat Example.
Bluetooth and specifically Bluetooth Low Energy are emerging as the standard communication protocol for Internet of Things. If you want to start digging into what you can do the example should work right off the bat with the latest version of Android Studio.
I want to connect two phones over 3G or GPRS to send a stream of data continually. One phone will act as client that will send data and the other phone will act as the server to receive and display the same data. Is it possible to stream data without using a server?
No. You will have to use some kind of server definitely.
Not really, I have been working on a similar project using TCP/UDP packets, but the big issue is with finding the other phone.
The best way is to use a system similar to O-Auth to connect with an external server on the internet
and send/recive data through that, but I don't have much experience with that.
My project used UDP to find a server on a wifi network and get its ip, then connect to it through tcp,
but you just as easily use a server on the web to do it over any mobile data connection.
If you wanted I will gladly send you some of my tcp code as a starting point.
Swift
You can't connect two devices directly though the cellular data. You need an intermediate server.
If on the other hand you are going to connect them through wifi, then you can use sockets to connect both of them together.
If the distance between both the devices is less, then you can also try out transfer over bluetooth.
I want to write a program to access my Android phone's camera on my laptop wirelessly, so, my phone will act like a wireless webcam.
I want to implement the UDP ( or TCP ) protocol in Java to communicate between my laptop and phone.
I was thinking of making an ad-hoc wireless network in my laptop and connecting my phone to it first, and then write the code to create a server socket on my laptop and client socket on my phone.
I know this code will work for a "direct communication" between server and client. but will this method of ad-hoc network communication count as a "direct communication" ?
If not, what do I do to achieve this ?
Thank you, firstly for reading my whole problem, and,
thanks a lot if you can answer this for me
:)
First of all: Don't concentrate on ad-hoc networks. In most cases WiFi with infrastructure mode access points will be available. If on the road, all recent versions of Android are able to act as a wireless access point.
So let's assume both devices are connected to the same network and are able to reach each other (using the IP protocol) - in other word they are able to ping each other. The next issue you have to solve is: How do both applications find each other? Bonjour/Zeroconf might be a solution (see Are there any other Java libraries for bonjour/zeroconf apart from JMDNS?).
The next question is: What protocol you want to use? You mentioned TCP and UDP. In most cases UDP will be used for transmitting video data, because you have a lower latency and the video codecs are tolerant on missing packets.
With this information you can create a ServerSocket and (from the client side) know where to connect to it.
I have implemented a sip based real time voice transfer under the impression that two of my phones on the same WIFI network can communicate provided that they have each others IP addresses. However, I could not make it work... I am using rtp to transfer voice between these clients.
Also, it's come to my notice that using a PC on the WIFI network as server is better. Now, can I use this PC as a proxy server to establish a sip end to end connection? If yes, how?
Are there existing implementations for initializing a session? Specifically, if someone could give me an example on what address/ports I would need both of my clients to establish the connection to, it would be great.
If you have implemented correctly all the necessary parts that SIP protocol demands, then you have to install a SIP server on your PC and just create two accounts that the phones will connect with them on the server. I have tried with Android the Asterisk server, but I am sure that there will be many others out there...
By default SIP servers are listening on port 5060 using UDP. This port is used only for the initiation of the session (and other control messages) and NOT for the transfer of RTP packets.
So i want to create an Android application that would send data (in this case coordinates) from my Android device to a Java application on my MacBook via Wi-Fi.
I figured i would use TCP Sockets for the job, and my Android device would act as client while my MacBook as server.
My problem is that in reality hardcoding IP addresses is not the ideal techique for that, is there any way around this? Is using Sockets the best way to make an application like that?
Not getting into the best way to do it, but instead of static ips use a Dynamic Dns Service.
You could use dynamic DNS. With dynamic DNS, client (Macbook) registers its IP address with DNS server, which than serves it to other clients (Android) via normal DNS requests.
However, I'd recommend against this setup (server on notebook with DynDNS):
Your notebook might not be always available, due to personal reasons or network connectivity reasons.
Network address translation (NAT): most client networks (wlan, home networks, even mobile networks) use this technology which prevents initiating TCP connections from internet to internal network (inbound connections). This can be alleviated via port forwarding, but this can only be done on networks that you control.
Instead I'd suggest that you use a virtual private server (Linode) or a cloud solution.
Alternatively, if you don't want to setup/manage a server, than you could use an existing data exchange solution: email, twitter, xmpp, etc..