I cannot figure out how to send a UDP packet over a 4G LTE network from an Android app (no WiFi). Does anyone have any ideas or know where I can find some documentation? I need to write two android apps, one client and one server, so that I can send UDP packets with timestamps from one device to the other. This is to test 4G LTE network latency from device to device.
Please help!
Thanks!
You can use the DatagramSocket class:
http://developer.android.com/reference/java/net/DatagramSocket.html
This should work regardless of WiFi or mobile connection type, although you may find some mobile operators have some restrictions on UDP connections.
There are many existing Android Iperf apps that can be used for exactly what you are trying to do. I use Magic Iperf to do this type of testing myself.
Related
I need to connect multiple phones to each other using wifi, without there being any internet though.
So i was thinking if this can be done by turning on the hotspot on one phone and allow the others to connect to it, can this be done ?
Or is there any other way to connect multiple phones via wifi ?
Any help is appreciated .. thnQ
To send and receive UDP messages you can using the following technique:
https://code.google.com/p/boxeeremote/wiki/AndroidUDP
The simplest way to explain this is that the UDP packages can be transmitted on a network with no particular destination set. Applications can pick this up and then decide if they want to handle the message or not.
To connect the devices you can use either a mifi dongle or put one of the phones into tethering mode:
https://support.google.com/nexus/answer/2812516?hl=en
Of course this is limited in range to the hosting mifi or phone.
I'm making an application which needs to communicate to another app on another device. The only problem is that the IP addresses from the devices aren't allways the same. I want to client to find the server on a specific port, but how can I find devices on the network which have this port opened without me having to enter the server's ip on the client side? I've found Android's NsdManager, but that works from API level 16 and on. I'm developing with level 10.
Thanks in advance!
You can use Zero-configuration networking which can help to solve your problem.Have a look at following websites-http://www.multicastdns.org/ and http://en.wikipedia.org/wiki/Zero-configuration_networking.
You can also make use MDSND, check Bonjour implementation on Android for more info.
My apologies for not responding.
I solved this problem by broadcasting an UDP packet to all devices (255.255.255.255). Al devices listening in the specified port will respond and thereby the client will now know the server's IP address. TCP is used for further communication.
This shouldn't be too difficult.
The private ip address in question should be of the form 192.168.1.x (x being between 1 and 255)
And normally, I believe that number is assigned sequentially, so first I would check if
192.168.1.1 if not that one,
then I'd check
192.168.1.2 then
192.168.1.3 then
etc.
Broadcasting works in most cases, the link below shows how to do it from code:
[Send Broadcast UDP but not receive it on other Android devices
But there are exceptions:
Some phones doesn't recevie broadcasting package correcttly(HTC for example), i solved this problem by broadcasting from HTC phone and once other phone recevied the package, send a udp package to HTC phone(not through broadcasting)
If one of the device is act as hotspot, the broadcasting seems doesn't work at all, in this case, other devcie can try use the gateway ip(which is the hotsport device's ip)
Short version: Does the T-Mobile network allow incoming UDP packets?
Longer version:
I'm writing a small test app that connects two Androids over a mobile network. It works over LAN but not over 3g.
Most carriers block incoming TCP connections over their networks, Does the same restriction apply to incoming UDP?
I've recently been testing UDP port forwarding on 3G from T-Mobile Slovakia (Deutsche Telekom) and found that it's not possible. They are using Symmetric NAT which will prevent you from communicating endpoints between two peers because one peer's incoming port will depend on another peer's IP address. I wrote a bit more about it here.
I've not yet had problems with O2 Slovakia (Telefónica) in this regard.
EDIT: This may be irrelevant now given that the question is 5 months old, but since you mentioned building a test app, the best tutorial on NAT traversal I've found is IMO this one.
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.