开发者

Android: Telnet using Socket - missing last line

开发者 https://www.devze.com 2023-04-08 03:44 出处:网络
I\'m trying to write some MUD Client for android, and I run into problem with output from server. I can\'t get my app to show last line (Login prompt) in console..

I'm trying to write some MUD Client for android, and I run into problem with output from server. I can't get my app to show last line (Login prompt) in console..

try {
        Socket socket = new Socket("studnia.mud.pl", 4004);
        OutputStream out = socket.getOutputStream();
        PrintWriter output = new PrintWriter(out);
        output.println("Siema开发者_如何学JAVA, pisze klient mudowy pod androida wiec nie bijcie że testuje na studni. :(");

        BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line="1";
        while(line!=null){
            line = input.readLine();
            Log.i("Socket", line);
        }
        socket.close();
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


readLine() does not return the login prompt line because this line is not yet complete - there is no line-termination character until the login name has been entered. In order to get the partial line with the prompt, you cannot use readLine(); try something like while (input.ready()) { int c = input.read(); ... } or input.read(cbuf, 0, len).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号