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

The Archive Base Latest Questions

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

Having some irritating trouble with Java sockets, my application seems to be failing at

  • 0

Having some irritating trouble with Java sockets, my application seems to be failing at a very basic level. Part of my application requires writing filenames across a TCP connection. The receiver code is as follows:

ServerSocket serverSocket = new ServerSocket(4445); 
Socket socket = serverSocket.accept();      
BufferedReader reader = new BufferedReader(
            new InputStreamReader(socket.getInputStream()));
String filename = reader.readLine();

While my sender code is as follows:

    Socket socket = new Socket(InetAddress.getLocalHost(), 4445);
    PrintWriter writer = new PrintWriter(socket.getOutputStream());
    writer.write("Test.jpg");

Very, very basic stuff here, but for some reason, I’m getting a SocketException: Connection Reset when I run this? This is the full stack trace:

Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at FileReceiver.main(FileReceiver.java:11)

with the FileReceiver.java:11 line being the one where the reader.readLine() call is made. I can’t for the life of me figure out what is going wrong, similarly basic use of TCP sockets has always worked for me in the past, why is this happening now?

  • 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-27T00:41:30+00:00Added an answer on May 27, 2026 at 12:41 am

    You need to combine what both Nick and Nikolai said:
    You need to write with println (since readLine is expecting an end-of-line) and you need to flush your writer before closing it.

     Socket socket = new Socket(InetAddress.getLocalHost(), 4445);
     PrintWriter writer = new PrintWriter(socket.getOutputStream());
     writer.println("Test.jpg");
     writer.flush();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having some trouble with what should be a very simple scenario. For example purposes,
I´m having some trouble deciding in which way to go... I've got this application
Hey having some trouble trying to maintain transparency on a png when i create
Basically having some trouble with using Hover to hide or show an item. The
Been having some trouble implementing a single-column index in LaTeX. I've been employing the
Im having some trouble with an oracle database. Every time i try to connect,
having some trouble with hitTestObject and now Flash is telling me it can't convert
Having some trouble w/ IE7. IE8, Chrome, Firefox all work fine, but IE7 won't
Having some trouble sending properly formatted HTML e-mail from a PHP script. I am
Having some invokeMethod that takes in (java.lang.String method_name, Object[] params, Class[] params_classes) How would

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.