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

  • SEARCH
  • Home
  • 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 7850833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:59:06+00:00 2026-06-02T18:59:06+00:00

I am trying to read byte[] that is being send from a client to

  • 0

I am trying to read byte[] that is being send from a client to a server.

This is my client code…

 din = new DataInputStream(socket.getInputStream());
 dout = new DataOutputStream(socket.getOutputStream());

 Cipher cipher = Cipher.getInstance("RSA"); 
 // encrypt the aeskey using the public key 
 cipher.init(Cipher.ENCRYPT_MODE, pk);

 byte[] cipherText = cipher.doFinal(aesKey.getEncoded());
 dout.write(cipherText);

And this is my server code…

 DataInputStream dis = new DataInputStream(socket.getInputStream());          
 DataOutputStream dos = new DataOutputStream(socket.getOutputStream());

 String chiper = dis.readUTF();
 System.out.println(chiper);

However, the dis.readUTF(); line fails with an exception…

java.io.EOFException at java.io.DataInputStream.readFully(DataInputStream.java:197)
    at java.io.DataInputStream.readUTF(DataInputStream.java:609)
    at java.io.DataInputStream.readUTF(DataInputStream.java:564)
    at gameserver.ClientHandler.run(GameServer.java:65)

Could someone please help me understand why this doesn’t work.

  • 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-06-02T18:59:08+00:00Added an answer on June 2, 2026 at 6:59 pm

    For starters, if you write a sequence of (encrypted!) bytes at one end, and trying to read a UTF-formatted string at the other end…you’re going to have a bad time.

    I’d suggest that on the client side you should do something like

    dout.writeInt(cipherText.length);
    dout.write(cipherText);
    

    and then on the server side you should do something like

    int byteLength = dis.readInt(); // now I know how many bytes to read
    byte[] theBytes = new byte[byteLength];
    dis.readFully(theBytes);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to read in image file from a server , with the code
I am trying to read a binary file from a program that writes a
i am trying to disconnect a client from a server but the server still
I am trying to read ASCII text response from a tcp open streaming socket
Im trying to read a column of String values from my DB. Im trying
I'm trying to read the response stream from an HttpWebResponse object. I know the
I'm trying to read a file that I have a web address for into
I'm trying to read a csv file that holds several values in every cell
I'm trying to read a binary file that is in the following format: number
Here's my code: private void OnReceive(IAsyncResult result) { NetStateObject state = (NetStateObject)result.AsyncState; Socket client

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.