Solved

java.net. SocketException: Descriptor not a Socket

Posted on 1997-08-20
2
1,836 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 264
ejb stateless example 2 66
pagenation logic how it is working in my code 1 80
learn programming 8 94
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

732 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