DEBUG / SntpClient (60): request timed out: java.net.SocketException: address family is not supported by the protocol

I am running a server on a Linux console that is written in C and creates a client in android. I don't get any error in DDMS, but after Debug messages come

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

but the message will not be sent to the server. But if you create a client in C or java, it works 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; } }; } 
+6
android
source share
3 answers

SNTP is a network time protocol. The emulator is trying to get the actual time. I think this has nothing to do with your application.

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

+2
source share

Do not forget to add

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

in the manifest.

It helps me.

+1
source share

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 feedback device. To get "localhost" as your server, you will need 10.0.2.2.

+1
source share

All Articles