没有java客户端/服务器应用程序的输出 [英] no output for java client/server app

查看:110
本文介绍了没有java客户端/服务器应用程序的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您之前的所有回复,非常有帮助。
我有另一个Q服务器/客户端应用程序。我gt服务器/客户端之间的连接。
但是现在当我输入内容时,没有任何反应。我实现的run()侦听输入并显示它们。看来这个方法不起作用(这就是为什么我猜没有输出)

thank u for all ur previous responses which are very helpful. I have another Q for server/client app. I gt the connection between server/client. But now when I type something, nothing happens. The run() that I implement listens to input and display them. It seems that this method is not working (thats why there no output I guess)

这是run()(收到监听和显示消息)和send() (发送消息)

This is the run() (listen and display message received) and the send() (send message)

谢谢

public void run(){//watch for incoming communication
        String msg;

        try{//loop reading lines from the client and display msg
            while ((msg = serverIn.readLine()) != null) {
                System.out.println("msg received"+msg);
            }
        }catch (IOException e) {
            System.err.println(e);
        }   
    }

    public void send(String msg){//send outgoing message
        System.out.println("in the send()");
        serverOut.println(msg);
    }

一些可能有用的信息:
这些方法在课堂上我打电话给他们

Some information that could be helpful: Those method is in class I call them by

someClass.start() (someClass extends Thread class)
someClass.send()


推荐答案

看起来你需要刷新输出流。

It looks like you need to flush the output stream.

  public void send(String msg){//send outgoing message
        System.out.println("in the send()");
        serverOut.println(msg);
serverOut.flush();
    }

假设 serverOut PrintWriter 它似乎是什么?

这篇关于没有java客户端/服务器应用程序的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆