English 中文(简体)
Java 客户端 - 服务器不重复响应
原标题:Java Client - Server not repeat respond

//Edit 13:25 Client Console

Connect to server<br />
Repsonded: Tue May 22 13:23:28 CEST 2012<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Repsonded: Tue May 22 13:23:38 CEST 2012<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />
Connect to server<br />
Not run: java.net.SocketException: Software caused connection abort: recv failed<br />
Disconnect to server<br />

< 强力 > 服务器控制台 < /强 >

Server Initialized<br />
111111<br />
111111<br />
111111<br />
111111<br />
111111<br />
111111<br />
111111<br />
111111<br />
111111<br />
111111<br />
111111<br />
Error(run): java.net.SocketException: Connection reset by peer: socket write error<br />


Server load data and not return repead "Repsonded: Tue May 22 13:23:38 CEST 2012" or client not ouput print.
最佳回答

问题在于您的服务器执行。 您没有在运行的语句中循环, 正在检查从此连接中获取新的commmtion 消息。 您读过一次信息, 然后关闭最后语句中的连接 :

 @Override
    public void run() {

        try {

            BufferedInputStream is = new BufferedInputStream(connection.getInputStream());
            InputStreamReader isr = new InputStreamReader(is);
            ...
        finally {
            try {
                connection.close();

当然, 您的服务器有一个连接连接请求的循环检查, 所以如果客户端在每封信发送后试图再次连接到服务器, 将会有效, 但您的客户端只发送一个请求( 在主语句开头 ) 。

So, what I would advice you to do: Server-side, setup the streams etc in the run statement, and once they are set up enter a infinte loop with while(true), and in that loop have the server read from the input stream, and if read() does not return null, print the message. This will cause the server check for incomming data from that client, once you get a string that s not null it will print it (and trigger a response if you want).

客户端同样, 您需要一个循环, 以监听服务器的通信信件 。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签