简体   繁体   English

在Java中重置Socket输入流

[英]Reset Socket input stream in Java

I am developing chat application in Java, allowing more users to connect to server. 我正在用Java开发聊天应用程序,允许更多用户连接到服务器。 I managed to establish communication between clients, but the problem is when client sends message for the first time server recieves it and send it to destination client. 我设法在客户端之间建立通信,但是问题是,当客户端第一次发送消息时,服务器第一次接收到该消息并将其发送到目标客户端。 But when the same client sends message for second time (and so on) server recieves message it receieved for the first time, so destination client is recieving the same message over and over again... I send object of type Message which I defined in another class.. 但是,当同一客户端第二次发送消息(依此类推)时,服务器第一次接收到该消息,因此目标客户端一遍又一遍接收相同的消息...我发送的消息类型是我定义的对象另一堂课

I googled a little bit, and found out, that the problem is in stream and it should be reseted after each data had gone through stream. 我在Google上搜索了一下,发现问题出在流中,应该在每个数据流通过后重设该问题。 Output stream is possible to reset, but it doesent help. 可以重置输出流,但是它确实没有帮助。 When I try to reset input stream I get an error. 当我尝试重置输入流时,出现错误。 I runned out of ideas, has anybody got one? 我没有想法,有人知道吗?

It sounds like you need to call ObjectOutputStream.reset(). 听起来您需要调用ObjectOutputStream.reset()。 See the Jqvadoc for why. 有关原因,请参见Jqvadoc。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM