Solved

java.net. SocketException: Descriptor not a Socket

Posted on 1997-08-20
2
1,775 Views
Last Modified: 2008-03-17
What in god's name does this mean?  I'm passing a socket to the constructor of a Thread subclass.  This class consists of ONLY this constructor and a run() method that prints to the output stream of the socket. When I call the run() explicitly it WORKS. But, when I call start() on the object (which call the run() method) it gives me the message in the title.  WHY?

e.g. (note I'm leaving out code for simplicity, including the try & catch block where I caught the error, but it occurs when I flush the BufferedStreamWriter)

import java.net.Socket;
import java.io.*;
public class a extends Thread{
    Socket moSocket = null;
    public a(Socket poSocket){
      moSocket = poSocket;
    }
    public void run(){
      //Assume that I defined a BufferedStreamWriter with       //the socket already.
      bsw.write("Testing");
      bsw.flush();
    }
}

 
0
Comment
Question by:ho174
2 Comments
 

Author Comment

by:ho174
ID: 1225442
Forgive me for my forgetfulness.  There is no BufferedStreamWriter, rather it was a BufferedWriter that encapsulated the OutputStreamWriter, which encapsulated the Socket.getOutputStream().  This note was just for clarification, I still have that error.  Thanks for the help
0
 
LVL 2

Accepted Solution

by:
aleshka earned 40 total points
ID: 1225443
It look like you do something "bad" with this socket in method which calls a's start(), directly after this call. (for example: simple close the socket). So, if you call run method, which doesn't returns immediately - its ok, but when you try to call start, which will run the new thread and return at the same time, you have time to kill the socket before it will start to work.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question