小编raj*_*kar的帖子

readUTF中的EOFException

EOFException在使用readUTF()方法时遇到问题,请告诉我如何解决此问题,并建议如何readUTF()在其他网络上传输套接字信息

import java.io.*;
import java.net.*;

public class GreetingServer {
    public static void main(String args[]) {
        String servername =args[0];
        int port = Integer.parseInt(args[1]);

        try {
            System.out.println("Server Name "+ servername +"Port"+port);

            Socket client = new Socket(servername,port);
            System.out.println("Just connected to"+ client.getRemoteSocketAddress());
            OutputStream outs = client.getOutputStream();
            DataOutputStream dout = new DataOutputStream(outs);
            dout.writeUTF("Hello From"+client.getRemoteSocketAddress());
            InputStream in = client.getInputStream();
            DataInputStream din = new DataInputStream(in);
            System.out.println("Server Says"+ din.readUTF());
            client.close();
        }
        catch (EOFException f) {
            f.printStackTrace();
        }
        catch(IOException e) {
            e.printStackTrace();
        } …
Run Code Online (Sandbox Code Playgroud)

java eofexception

4
推荐指数
2
解决办法
9395
查看次数

标签 统计

eofexception ×1

java ×1