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.
Related
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
Hi I am new to socket programming.I am developing a client- server application. My server will a Java application. My client will be an android App. what i want to do is that i want to send data over both the channels i.e WiFi and 3G network. Is this Possible to send some packets over WiFi and some over 3G.
Is such a mechanism possible. If yes how can i accomplish this?
what I thought that i will create two sockets at client side and bind them to their specific IP's i.e bind one socket with wifi IP and other with 3G network IP.
Is there any provision of binding IP's with sockets at client side.
I have a UDP server running on my private network.I have a device which is beyond NAT which sends UDP packets to my server through public IP. I am able to receive the UDP packets, parse them and I can view the pay load, src and dest port. Now I need to send an ACK message to that device so I have captured the ip and port numbers and sending a UDP packet to it. But I could not able to view any UDP packets in that device.
My question is as my Device is beyond NAT the IP address and port number I am getting is NAT's or the actual device's ?
How to send the UDP packet to that device through NAT ?
My question is as my Device is beyond NAT the IP address and port number I am getting is NAT's or the actual device's ?
The IP and Port you identify from the packet are those which the NAT created a mapping for the client. In simple words, it is the IP and Port of the NAT to which the device is connected.
How to send the UDP packet to that device through NAT ?
You need to reply on the IP and port detected by the server from the packet it received from client.
More clearly you need to implement UDP Holepunching.
I guess you should first understand the networking issues regarding connection to devices working under a NAT. Various RFCs are available for NAT Traversal and UDP Punching.
Here are some sources:
http://en.wikipedia.org/wiki/Network_address_translation
http://en.wikipedia.org/wiki/UDP_hole_punching
https://www.rfc-editor.org/rfc/rfc4787
https://www.rfc-editor.org/rfc/rfc5128
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?
I need to send messages to Android phones through P2P on 3G connection.
Sending and receiving works perfectly on lan ip addresses(on wi-fi) but not on 3g or 2g.
On 3g I send a message but it never appears on the other end of the line.
Can anyone tell me how to make a connection ?
What port to use ?
Thanks,
DataSmith
DataSmith, what you refer to as internal and external IP address is most probably private IP address and public IP addresses. Private IP address are valid only on the lan where the device is located. This is why you can connect to other peers on the LAN.
However, there is no way you can connect alone to peers on other LANs (unless they have a public IP address on their LAN, which most probably is not the case). You need to learn about IP address translation and NAT traversal to achieve this. You can check the Practical JXTA II book available online for reading at Scribd.