Java socket, Is that a dead lock or what?(Java套接字,那是死锁还是什么?)
问题描述
我有一个在服务器端使用套接字的客户端-服务器程序,并且读写是以这种方式发生的
I have a client-server program using socket on the server side and read and write is happening in that way
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);
同样在 cilent(android) 方面...
and similarly on the cilent(android) side...
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();
}
问题是,连接建立后程序卡住了,不报错也不例外;停下来
The problem is that, after the connection is established the program stuck their, giving no error no exception; just stop
推荐答案
这是一个死锁,你必须先创建并刷新 ObjectOutputStream.这是因为 ObjectInputStream 在继续之前会读取 OOS 发送的 header.
Its a deadlock, you must create and flush the ObjectOutputStream first. This is because ObjectInputStream reads the header sent by the OOS before continuing.
这篇关于Java套接字,那是死锁还是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java套接字,那是死锁还是什么?
基础教程推荐
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
