我已经编写了一个EchoServer,如果相应地发送了数据,它将使用字符串ack进行响应。
我的委托人是这样的..。为了从服务器接收ack应答,"echoSocket“将接收到的数据放入my ObjectInputStream中。只有当我注释掉这些部分时,客户端才能正常工作
echoSocket = new Socket(server_name, tcp_port);
System.out.println(" *** Connected to " + server_name + " ***");
System.out.println("Press Enter to send your message.");
out = new ObjectOutputStream(echoSocket.getOutputStream());
in = new ObjectInputStream(echoSocket.getInputStream());
out.flush();
String message = System.console().readLine();
while(!message.equals("quit")) {
// problem
if (in.readObject().equals(ack))
System.out.println("ACKed");
in.close();
// problem ends
out.flush();
out.writeObject(message);
System.out.println("Sending: " + message);
message = System.console().readLine();
out.flush();
}有人知道为什么它不发送我的字符串吗?
谢谢,马吕斯
发布于 2009-11-23 06:43:15
在套接字上使用对象流并不是一个真正值得推荐的想法。您可以考虑使用完整的web服务或RMI。
如果您读取缓冲区,并确保在尝试使用对象流反序列化之前拥有整个业务,它可能会工作得更好。
发布于 2009-11-23 07:35:31
为什么不使用hessian库呢?
它的工作方式就像一个护身符:http://karussell.wordpress.com/2009/04/10/hessian-web-service-protocol-hello-world-example/
或者尝试spring remoting (它不是那么轻量级)
http://static.springsource.org/spring/docs/2.5.x/reference/remoting.html
发布于 2009-11-23 06:51:46
看起来客户端正在尝试在写入消息之前读取确认。
https://stackoverflow.com/questions/1780281
复制相似问题