DEBUG / SntpClient(60):请求时失败:产生java.net.SocketException:地址族不支持的协议 [英] DEBUG/SntpClient(60): request time failed: java.net.SocketException: Address family not supported by protocol
问题描述
我米运行的服务器上的Linux控制台其C语言编写,在Android中创建客户端。我还没有得到关于DDMS任何错误,但下面的调试信息来
11-12 20:38:06.787:DEBUG / SntpClient(60):请求时失败:
java.net.SocketException异常:地址族不支持的协议
但消息不会去到服务器。但是,如果在C或Java中创建客户端是工作的罚款。 任何建议。
公共类UDPDemo延伸活动{
私人的EditText mEditText;
私人按钮sendButton;
私人DatagramSocket的client_socket;
私有静态的InetAddress ip地址;
私人字节[] SEND_DATA =新的字节[1024];
静态{
尝试 {
ip地址= InetAddress.getByName(127.0.0.1);
}赶上(UnknownHostException异常E1){
e1.printStackTrace();
}
}
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
mEditText =(EditText上)findViewById(R.id.EditText01);
sendButton =(按钮)findViewById(R.id.Button01);
sendButton.setOnTouchListener(发送);
}
OnTouchListener发送=新OnTouchListener(){
@覆盖
公共布尔onTouch(视图V,MotionEvent事件){
如果(event.getAction()== MotionEvent.ACTION_UP)
尝试 {
client_socket =新的DatagramSocket();
字符串数据= mEditText.getText()的toString()。
SEND_DATA = data.getBytes();
DatagramPacket类Sent_Packet的=新的DatagramPacket(SEND_DATA,
send_data.length,ip地址,5000);
client_socket.send(Sent_Packet的);
mEditText.setText();
}赶上(IOException异常E){
的System.out.println(UDPDemo.enclosing_method()错误+ e.getMessage());
e.printStackTrace();
}
返回true;
}
};
}
SNTP是网络时间协议。仿真器试图获取的实际时间。我想,这无关你的应用程序。
从:<一href="http://developer.appcelerator.com/question/117495/javanetsocketexception-address-family-not-supported-by-protocol" rel="nofollow">http://developer.appcelerator.com/question/117495/javanetsocketexception-address-family-not-supported-by-protocol
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;
}
};
}
SNTP is the Network Time Protocol. The emulator tries to fetch the actual time. I think, this has nothing to do with your app.
这篇关于DEBUG / SntpClient(60):请求时失败:产生java.net.SocketException:地址族不支持的协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!