UDP server doesnt accept calls from outside.
Posted
by rayman
on Stack Overflow
See other posts from Stack Overflow
or by rayman
Published on 2010-05-12T11:24:14Z
Indexed on
2010/05/12
11:44 UTC
Read the original article
Hit count: 247
android
|android-sdk
Hi, ive implement simple udp server on my Android device.(sdk 1.5) it works fine when i am runnning a local client on the phone sends through it trigger to my server.
but when i try to get udp call from an outside server to my phone, it doesnt work. already make sure the outside server isnt blocked by firewall and it's sending the udp trigger to the right port, which my phone is listening to.
i used natstat on the phone and checked that the phone is realy listening to the it's local ip and the port ive setted it to.
here is my code of the server:(on the device)
// server will listen to one client
try
{
Thread udpServerThread = new Thread()
{
@Override
public void run()
{
try
{
// Retrieve the ServerName
InetAddress serverAddr = InetAddress
.getByName("localhost");
Log.d("UDP", "S: Connecting...");
// Create new UDP-Socket
socket = new DatagramSocket(SERVERPORT,serverAddr);
byte[] buf = new byte[17];
// * Prepare a UDP-Packet that can contain the data we
// * want to receive
DatagramPacket packet = new DatagramPacket(buf,
buf.length);
Log.d("UDP", "S: Receiving...");
// wait to Receive the UDP-Packet
socket.receive(packet);
Log.d("UDP", "S: Received: '"
+ new String(packet.getData()) + "'");
acceptedMsg=new String(packet.getData());
notifyService(acceptedMsg);
Log.d("UDP", "S: Done.");
} catch (Exception e)
{
Log.e("UDP", "S: Error", e);
}
}
};
udpServerThread.start();
}
catch (Exception E)
{
Log.e("r",E.getMessage()) ;
}
so as i said, when i try it with local client(seperate thread) which sends udp trigger it works fine, but when i take this client implementation and put it on an outside real server, after UDP being sent, the phone doesnt respond to it.
any idea?
thanks,
ray.
© Stack Overflow or respective owner