gpt4 book ai didi

android - DEBUG/SntpClient(60) : request time failed: java.net.SocketException:协议(protocol)不支持的地址族

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:07:04 25 4
gpt4 key购买 nike

我在用 C 编写的 Linux 控制台上运行服务器,并在 android 中创建客户端。我在 DDMS 上没有收到任何错误,但是出现了调试消息

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

但是消息不会发送到服务器。但是如果在 C 或 Java 中创建客户端它工作正常。任何建议。

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;
}
};
}

最佳答案

记得加

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

进入 list 。

这对我有帮助。

关于android - DEBUG/SntpClient(60) : request time failed: java.net.SocketException:协议(protocol)不支持的地址族,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4163375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com