我有一个使用socket的客户端-服务器程序,服务器端进行读写操作。
soc = serversocket.accept();
System.out.println("Accepted");
in = new ObjectInputStream(soc.getInputStream());
out = new ObjectOutputStream(soc.getOutputStream());
if(in.readUTF() == null ? " " != null : !in.readUTF().equals(" "))
{
diskinfo.setPath(in.readUTF());
}
Item[] pac = diskinfo.get();
out.writeObject(pac);
在客户端(Android)方面同样如此...
Log.v("read", "item");
soc = new Socket(InetAddress.getByName("10.0.2.2"), 3838);
output = new ObjectOutputStream(soc.getOutputStream());
input = new ObjectInputStream(soc.getInputStream());
try
{
output.writeUTF(path);
packets = (Item[]) input.readObject();
}
catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
问题在于,连接建立后程序会卡住,没有出现任何错误或异常,只是停止了。