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 7561277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:07:23+00:00 2026-05-30T13:07:23+00:00

I’m having problem with a server I’m building. I reduced the problem to a

  • 0

I’m having problem with a server I’m building. I reduced the problem to a simple server-client pair in Java. I’m sending bytes 0 to 255. The problem is values from 128 (0x80) to 159 (0x9F) are being received by InputStream as a 63 (0x3F). This is killing my binary transfers. Why could this be happening?

This the output I get, see how after value 127 there are a bunch of 63’s:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 8
3 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 10
7 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 12
7 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
63 63 63 63 63 63 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 17
5 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 19
5 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 21
5 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 23
5 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 25
5

This is my server code, based on the KnockKnockServer example:

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

public class Server {
        public static void main(String[] args) throws IOException {

                ServerSocket serverSocket = null;
                try {
                        serverSocket = new ServerSocket(4444);
                } catch (IOException e) {
                        System.err.println("Could not listen on port: 4444.");
                        System.exit(1);
                }

                Socket clientSocket = null;
                try {
                        clientSocket = serverSocket.accept();
                } catch (IOException e) {
                        System.err.println("Accept failed.");
                        System.exit(1);
                }

                OutputStream out = clientSocket.getOutputStream();
                InputStream in = clientSocket.getInputStream();

                while (true)
                {
                    int val = in.read();
                    if (val < 0)
                        continue;

                    System.out.print(val);
                    System.out.print(' ');
                    if (val == 255)
                        break;
                }

                out.close();
                in.close();
                clientSocket.close();
                serverSocket.close();
        }
}

And this is my client’s code, based on the EchoClient example:

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

public class Client {
        public static void main(String[] args) throws IOException {

                Socket echoSocket = null;
                PrintWriter out = null;
                BufferedReader in = null;

                try {
                        echoSocket = new Socket("localhost", 4444);
                        out = new PrintWriter(echoSocket.getOutputStream(), true);
                        in = new BufferedReader(new InputStreamReader(
                                                                                echoSocket.getInputStream()));
                } catch (UnknownHostException e) {
                        System.err.println("Don't know about host: taranis.");
                        System.exit(1);
                } catch (IOException e) {
                        System.err.println("Couldn't get I/O for "
                                                             + "the connection to: taranis.");
                        System.exit(1);
                }

        for (int i = 0; i < 256; i++)
            out.print((char) i);
        out.flush();

        out.close();
        in.close();
        echoSocket.close();
        }
}

Run this and tell me if you get the same weird problem. Please help me. Thank you!

  • 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-30T13:07:24+00:00Added an answer on May 30, 2026 at 1:07 pm

    From the documentation of PrintWriter at http://docs.oracle.com/javase/1.4.2/docs/api/java/io/PrintWriter.html

    Print formatted representations of objects to a text-output stream.
    This class implements all of the print methods found in PrintStream.
    It does not contain methods for writing raw bytes, for which a program
    should use unencoded byte streams.

    So you are probably using the wrong tool for this job.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.