DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol
Asked Answered
F

3

6

I m running server on Linux console which written in C and creating client in android. i have not getting any error on DDMS but following Debug message come

11-12 20:38:06.787: DEBUG/SntpClient(60): request time failed: 
java.net.SocketException: Address family not supported by protocol

but message will not go to the server. But if create client in C or java it working fine. any suggestion.

public class UDPDemo extends Activity {
    private EditText mEditText;
    private Button sendButton;
    private DatagramSocket client_socket;
    private static InetAddress IPAddress;
    private byte[] send_data = new byte[1024];
    static{
    try {
     IPAddress =  InetAddress.getByName("127.0.0.1");
 } catch (UnknownHostException e1) {
 e1.printStackTrace();
 }
} 

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mEditText = (EditText)findViewById(R.id.EditText01);
    sendButton = (Button)findViewById(R.id.Button01);
    sendButton.setOnTouchListener( send);
 }
OnTouchListener send = new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
  if( event.getAction() == MotionEvent.ACTION_UP)
  try {  
      client_socket = new DatagramSocket();
      String data =  mEditText.getText().toString();
      send_data = data.getBytes();

      DatagramPacket send_packet = new DatagramPacket(send_data,
               send_data.length, IPAddress, 5000); 

client_socket.send(send_packet);
mEditText.setText("");
  }catch (IOException e) {
    System.out.println("UDPDemo.enclosing_method() error"+e.getMessage());
   e.printStackTrace();
  }
 return true;
 }
};
}
Foreconscious answered 12/11, 2010 at 9:50 Comment(2)
We are seeing the same, but all the time. It happens randomly and when it occurs we need to open a new HTTP connection to the server. Could the problem be introduced in one of the latest Android versions 2.2 or 2.3. We have not seen any issue on real devices. Which version are you using? Have you tested on a real device?Appendicular
I am using android 2.1. I don't have any problem with real devices. It is working fine for me because I am compiling server (which is in C) with arm complier that android uses for comping C apps.(If you check ndk documentation).Foreconscious
R
2

Remember to add

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

into the manifest.

It helped for me.

Rafiq answered 16/2, 2011 at 13:35 Comment(0)
B
2

SNTP is the Network Time Protocol. The emulator tries to fetch the actual time. I think, this has nothing to do with your app.

From: http://developer.appcelerator.com/question/117495/javanetsocketexception-address-family-not-supported-by-protocol

Baxy answered 20/1, 2012 at 6:0 Comment(0)
A
1

I know this is old but I believe this is your problem:

IPAddress =  InetAddress.getByName("127.0.0.1");

Android uses 127.0.0.1 as its own loop back device. To get "localhost" aka your server, you will need 10.0.2.2 instead.

Alverta answered 22/9, 2011 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.