我正在开发针对android的移动应用程序。在那里,我创建套接字并在Android手机和Windows应用程序(它运行在PC,笔记本电脑上)之间传输数据。我使用的Android 2.3什么是Android中java.net.Socket的默认超时值?
测试移动三星Galaxy弹出
PC和移动设备通过USB连接tithering。
数据传输正确。
但是,一个问题是在应用程序中,通过从系统中拔出移动usb caple取消了抖动,然后我抛出异常。
但有些时候它没有通过它只是等待任何异常,阅读
所以,请把默认套接字超时时间的Android
我的示例代码下面给出的数据插槽也未关闭等待
Socket socket=null;
DataOutputStream dos=null;
OutputStream os=null;
InputStream is=null;
DataInputStream dis=null;
try
{
Log.i(tagName, "b4 creating socket");
socket=new Socket(this.getIpAddress(),this.getPort_number());
is=socket.getInputStream();
dos=new DataOutputStream(os);
dis=new DataInputStream(is);
}
catch(UnknownHostException unknown_ex)
{
Log.i(tagName, "Exception host unknown : "+unknown_ex.toString());
unknown_ex.printStackTrace();
}
catch(IOException ioe_ex)
{
Log.i(tagName, "ioe Exception : "+ioe_ex.toString());
ioe_ex.printStackTrace();
}
catch(Exception ex)
{
Log.i(tagName, "Exception : "+ex.toString());
ex.printStackTrace();
}
if(dos!=null)
{
try
{
dos.close();
}
catch(Exception ex)
{
}
}
if(dis!=null)
{
try
{
dis.close();
}
catch(Exception ex){}
}
if(socket!=null)
{
try
{
socket.close();
}
catch(Exception ex)
{
}
}
socket=null;dos=null;dis=null;
Log.i(tagName, "MySocketConnection.connectMe() - end");
当我使用的代码
Socket.getSoTimeout()
然后它返回0.
请所有都给你的想法。
当你调用'Socket.getSoTimeout()'时,你会得到什么值? –