Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6179749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:43:30+00:00 2026-05-24T00:43:30+00:00

I am new to networking and I am getting an EOFException when I am

  • 0

I am new to networking and I am getting an EOFException when I am trying to run the MyClient.java.

MyServer.java

public class MyServer {
    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(4321);
        } catch (IOException e) {
            e.printStackTrace();
        }
        while(true) {
            try {
                Socket socket = serverSocket.accept();
                OutputStream os =socket.getOutputStream();
                OutputStreamWriter osw = new OutputStreamWriter(os);
                BufferedWriter bw = new BufferedWriter(osw);
                bw.write("Hello networking");

                bw.close();
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

MyClient.java

public class MyClient {
    public static void main(String[] args) {
        Socket socket = null;
        try {
            socket = new Socket("127.0.0.1", 4321);
            InputStream is = socket.getInputStream();
            DataInputStream dis = new DataInputStream(is);
            System.out.println(dis.readUTF());

            dis.close();
            socket.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (ConnectException e) {
            System.err.println("Could not connect");
        } catch (UTFDataFormatException e) {
            System.err.println("if the bytes do not represent a valid modified UTF-8 encoding of a string");
        } catch (EOFException e) {
            System.err.println("if this input stream reaches the end before reading all the bytes");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

I get if this input stream reaches the end before reading all the bytes for the error and the error seems to arise from the dis.readUTF() call.

Could someone help me understand what am I missing? I am trying just trying to read what the server writes to the client when it gets connected, that is Hello networking.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:43:31+00:00Added an answer on May 24, 2026 at 12:43 am

    the problem is in your server code
    you should use DataOutputStream.writeUTF(String str) to write to socket if you want to read it with the DataInputStream.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to UDP/networking programming, and I am trying to create a chat
I'm new to Windows networking, and I am trying to find out which PORT
I have been trying to get a simple networking test program to run with
I am unable to do any networking in Java when i run a simple
in android I am getting the following error: NativeStart.main(String[]) line: not available [native method]
I am new to programming. I have lots of interest in networking and want
New class is a subclass of the original object It needs to be php4
New to Linux programming in general. I am trying to communicate with a kernel
new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
New day, new problem :-) Code: Client Side: void abw_Closed(object sender, EventArgs e) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.