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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:48:46+00:00 2026-06-04T13:48:46+00:00

I am making a chat room using simple socket-socket connections. I have a server

  • 0

I am making a chat room using simple socket-socket connections.
I have a server and client program. The server runs on port 225, and then when I run the client on port 225 so that they can read/write to the sockets, the client instantly stops with the error message

java.net.SocketException: Connection resetJava Result: 1

Why is it throwing this exception? It connects, the line is printed to console, as shown:

try {
    client = new Socket(serverAdress, portNumber);
    System.out.println("Successful connection to server on port " + portNumber + ".");

So why might it not be able to connect?

This is the exception trace…

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at schoolroom10.SchoolRoomClient.SchoolRoomClientWindow.main(SchoolRoomClientWindow.java:85)

This is my Server code…

public class SchoolRoomServer {

    // 'server' will create the server over the local port:
    static ServerSocket serverSocket = null;

    //Socket for listening:
    static Socket clientcommunicate = null;

    //portnum is the number of the local port. Change to required port before running.
    static int portnum = 225;

    public static void main(String[] args) throws IOException{
        try {
            serverSocket = new ServerSocket(portnum);
        clientcommunicate = serverSocket.accept();
            Communicate c = new Communicate(Communicate.server);
            Thread t = new Thread(c);
            t.start();
        } catch (UnknownHostException uhe) {
            System.err.println(uhe);
            System.exit(1);
        } catch (IOException ioe) {
            System.err.println(ioe);
            System.exit(1);
        }


    } 
}

class Communicate implements Runnable {
    public static Socket server;
    Communicate(Socket server) {
        Communicate.server = server;
    }
    public void run() {
        String in = "";
        try {
            //i/o for clients:
            PrintStream output = new PrintStream(server.getOutputStream());
            BufferedReader input = new BufferedReader(new InputStreamReader(server.getInputStream()));
            String message;

            //Message handling:
            while(((message = input.readLine()) != null) && (!in.equals("."))) {
                output.println(message);
            }
        } catch (IOException ioe) {
            System.err.println(ioe);
        }
    }
}
  • 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-04T13:48:48+00:00Added an answer on June 4, 2026 at 1:48 pm

    ‘Connection reset’ usually means you have written to a connection that has already been closed by the other end. Generally speaking this is an applicaton protocol error. However in some circumstances, e.g. where the peer is a browser, or possibly in your case too, it is just an inevitable consequence of the fact that the peer may choose to go away at any time. In these cases, all you can do is close the socket and forget about the connection.

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

Sidebar

Related Questions

I'm making a simple cross platform chat program. I'm using wXWidgets for the GUI
I am making a simple chat GUI and I have written both a server
I am making a TCP chat server from a simple tutorial I found and
I'm making a simple chat program for me and my friends as a tech
This is similar to my last question. I'm making a simple tcp/ip chat program
I'm making simple XMPP client using Jabber-Net. To send simple message i'm using a
I am building a simple ajax chat client for a school project and have
I'm making a chat room with a text file. Very simple, but I don't
I am making a C# client / Java server chatroom, and everything works fine
I am making my first Android program. I am making a local chat program.

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.