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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:11:59+00:00 2026-06-14T01:11:59+00:00

UPDATE: Full code example: Server: ServerSocket serverSocket = new ServerSocket(8888); Socket client = serverSocket.accept();

  • 0

UPDATE:
Full code example:
Server:

ServerSocket serverSocket = new ServerSocket(8888);
Socket client = serverSocket.accept();
writer_ = new ObjectOutputStream(client.getOutputStream());
writer_.writeObject("This should be a solstice message normally.");
writer_.flush();

Client:

Socket clientSocket = new Socket(InetAddress.getLocalHost(), 8888);
ObjectInputStream reader = new ObjectInputStream(clientSocket.getInputStream());
Object obj = reader.readObject();
if (obj instanceof SolsticeMessage)
{
    SolsticeMessage message = (SolsticeMessage) obj;
    processMessage(message);
}
else
    System.out.println("Received a message of unknown type: " + obj.getClass());

When I run the code, client connects to the server, however It never prints the System.out.println() in the ‘else’ branch. Additionally, if I change the server as below:

ServerSocket serverSocket = new ServerSocket(8888);
Socket client = serverSocket.accept();
writer_ = new ObjectOutputStream(client.getOutputStream());
writer_.writeObject(message); // of type SolsticeMessage
writer_.flush();

to write a proper message, then the server throws broken pipe exception immediately.

The original question:
I am trying to write a simple server that waits for a client to get connected as follows:

ServerSocket serverSocket = new ServerSocket(8888);
Socket client = serverSocket.accept();
writer_ = new ObjectOutputStream(client.getOutputStream());

Then, making sure writer_ is not null, I try to write the following two messages to the client:

writer_.writeObject("This is a string.");
writer_.writeObject(message); // where message implements Serializable
writer_.flush();

Here is the client code:

Socket clientSocket = new Socket(InetAddress.getLocalHost(), 8888);
ObjectInputStream reader = new ObjectInputStream(clientSocket.getInputStream());
Object obj = null;
while ((obj = reader.readObject()) != null)
{
    SolsticeMessage message = (SolsticeMessage) obj;
    processMessage(message);
}

Contrary to my expectations (where both object should be written), the first objects (String) is sent successfully, however the second object (message) throws the following exception:

java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1756)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1257)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1211)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1395)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:333)
at com.kivancmuslu.www.solstice.server.SolsticeServer.sendMessage(SolsticeServer.java:146)
at com.kivancmuslu.www.solstice.server.listeners.ResourceChangeListener.processResourceChange(ResourceChangeListener.java:94)
at com.kivancmuslu.www.solstice.server.listeners.ResourceChangeListener.processResourceDelta(ResourceChangeListener.java:65)
at com.kivancmuslu.www.solstice.server.listeners.ResourceChangeListener.processResourceDelta(ResourceChangeListener.java:86)
at com.kivancmuslu.www.solstice.server.listeners.ResourceChangeListener.processResourceDelta(ResourceChangeListener.java:86)
at com.kivancmuslu.www.solstice.server.listeners.ResourceChangeListener.processResourceDelta(ResourceChangeListener.java:86)
at com.kivancmuslu.www.solstice.server.listeners.ResourceChangeListener.resourceChanged(ResourceChangeListener.java:31)
at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:291)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:285)
at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:149)
at org.eclipse.core.internal.resources.Workspace.broadcastPostChange(Workspace.java:395)
at org.eclipse.core.internal.resources.Workspace.endOperation(Workspace.java:1530)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:156)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Any ideas why string object is written and sent over the network without a problem, however my other serialized object causes this exception? I also attach my Serialized class below just in case it helps:

package com.kivancmuslu.www.solstice.logic;

public class ResourceChangedMessage extends SolsticeMessage
{
    /**
     * 
     */
    private static final long serialVersionUID = -2877650023886033398L;

    public static enum ResourceChangeType
    {
        ADDED, REMOVED
    }

    private final String projectName_;
    private final String relativeResourcePath_;
    private final ResourceChangeType resourceChangeType_;

    public ResourceChangedMessage(String projectName, String relativeResourcePath,
                                  ResourceChangeType resourceChangeType)
    {
        projectName_ = projectName;
        relativeResourcePath_ = relativeResourcePath;
        resourceChangeType_ = resourceChangeType;
    }

    public String getProjectName()
    {
        return projectName_;
    }

    public String getRelativeResourcePath()
    {
        return relativeResourcePath_;
    }

    public ResourceChangeType getResourceChangeType()
    {
        return resourceChangeType_;
    }
}

where SolsticeMessage is defined as:

package com.kivancmuslu.www.solstice.logic;

import java.io.Serializable;

public abstract class SolsticeMessage implements Serializable
{
    private static final long serialVersionUID = 4048501241385740686L;

    public abstract String toString();
}

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-06-14T01:12:00+00:00Added an answer on June 14, 2026 at 1:12 am

    I strongly suspect that the other end of the connection is closing it. For example, if it’s another Java program which has code of:

    Socket client = serverSocket.accept();
    reader_ = new ObjectInputStream(client.getInputStream());
    reader_.readObject();
    reader_.close();
    

    … then there’d be nowhere for your sending code to send the second object. Unfortunately you haven’t given us the code that’s listening. The above is my best guess though.

    EDIT: Now you’ve posted your server code, we can see the real problem. Here’s what it’s trying to read:

    while ((obj = reader.readObject()) != null)
    {
        SolsticeMessage message = (SolsticeMessage) obj;
        processMessage(message);
    }
    

    … but you’re sending it a String first. So it’s trying to cast a String to a SolsticeMessage, which will throw an exception – and presumably that is either bringing the whole process down, or at least ending up with a closed connection.

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

Sidebar

Related Questions

UPDATE 1: Here is the full code behind from the downloaded example, unedited: using
I am trying to change the code of the Searchable Dictionary example (full code
I need to update existing data or insert new data from client database say
Example: http://franklovecchio-playback.herokuapp.com/?log=true Full code: https://github.com/franklovecchio/playback You'll see the undefined attributes come through on the
Question: Can anyone please provide a full code example that shows how one does
UPDATE2: Tried rendering just a quad. UPDATE: The FULL code is here. Somebody can
My ascx control inside a container update panel does a full page refresh when
I have a folder full of 100-odd Access97 files. I need to update them
Update: Switching to IIS Express instead of the Visual Studio Development Server fixed the
Update - 12/17/2012 9am CDT : example has been updated with demo data and

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.