Referred to this link and i have done sample Client/Server Apps using android.The apps work well on GSM sim's able to send and receive packets,but on CDMA device i am not able to receive any packets but able to send packets.
Ip address details is drawn from this app
Whats going on here?
Related
I need to implement a messaging system for Android phones.
The server has static IP, it runs JAVA and it should send periodically UDP ping messages to android phones.
As I understand mobile phones have NAT IP.
The question is how server can send message to this IP.
I am trying to build an android application that connects two or more devices as a client/server(using socket).
But problem is in client device user need to manually put IP address of Server device to connect with server. But from the client i don't know the server IP Address. and i don't want to enter it manually.
is there any way to get IP address(programmatically) of server device that using same application and on the same network ?
Any help would be greatly appreciated.
Thank in advanced.
After trying many ways finally, I have got a solution which is
Network discovery using UDP broadcast (credit goes to this documentation)
(Thanks #Fildor for your suggestion to implement this service).
Solution
Using UDP packets and broadcasting them! This technique however is not optimal, but as long as we stay in one network this shouldn’t be a problem.
UDP packets however are fairly easy to work with.
Server implementation
Open a socket on the server that listens to the UDP requests.
Make a loop that handles the UDP requests and responses
Inside the loop, check the received UPD packet to see if it’s valid
Still inside the loop, send a response to the IP and Port of the
received packet
Client implementation
Open a socket on a random port.
Try to broadcast to the default broadcast address (255.255.255.255)
Loop over all the computer’s network interfaces and get their
broadcast addresses
Send the UDP packet inside the loop to the interface’s broadcast
address
Wait for a reply
When we have a reply, check to see if the package is valid
When it’s valid, get the package’s sender IP address; this is the
server’s IP address
CLOSE the socket! We don’t want to leave open random ports on someone
else’s computer
I want to
Recieve UDP message on device when it is connected through wi-fi
Know how to send udp message on device when it is connected to wi-fi
router as the sender on diffrent network
What i have tried
http://code.google.com/p/boxeeremote/wiki/AndroidUDP
What is working
UDP messeges are being recieved on device when it is connected
through 2g/3g data service
UDP messeges are being recieved when sender and reciever are both in
same network ( behind wi-fi router )
Any help/point in right direction is appreciated.
When the device is behind a wi-fi router, it has a private address so it isn't reachable from outside the private network, at least no without some extra work.
You need to do Hole Punching, is what applications like Skype do to receive UDP packets. Applications usually use a STUN server in order to achieve this.
The easiest alternative would be to have a server with a public address and make all the devices connect to the server with tcp/ip protocol. If you can't afford that you need to do Hole Punching.
Let's say I have two android mobile devices, connected to the same wireless network, and that network hasnt external/internet access.
Without third party software, is it possible to transfer data through wifi without knowing the ip from each other and without creating an hotspot? Something like we do on Windows (if 2 pcs are on same network, they can share information directly without internet access)
Starting with the basics, I would like to develop an application, where android phones on same network appears on a list , and then a user choose on of them and writes something - and if the other user have the same app running, appears that on his phone (and then he can reply of course - basically, a chat.
I know this make no practical sense, but believe makes all the sense for what I need to do (it's not a chat of course). If anyone knows anything, please help me - i found nothing.
Thanks in advance.
If you want to send data or messages from one phone to another using the network you will eventually need the IP address of the recipient phone. However, If you don't care about targeting specific phones you could always send UDP broadcast packets that each device on the network should receive.
If you don't want to manually specify an IP you'll need to create a discovery protocol that a phone uses to discover all the other phones on the network. You could do this buy scanning all available IP addresses and checking to see if they are a valid android phone. Or you could have each phone broadcast its presence on the network using a UDP broadcast packet sent to a predefined port.
Once you have discovered all the phones on the network its really up to you to decide how you want to send the data between phones and there are hundreds of examples of how to send data between devices/computers/processes using sockets.
I have made j2me SMS receive app.when i tried in in sun WTK it works
fine. It receives SMS in the emulator, but when I tried in Nokia n91, it does not receive it.
If you want to access the default sms inbox (port 0 of the sms protocol), you just can't do it with the usual virtual machine. The most you can do is to listen to a specific port and receive sms's sent to that port. If you want to do that, then the messages you send have to be specifically destined to that custom port.
Here it's a topic "discussing" this at the Nokia forum.
Regards.