Solved

java.net. SocketException: Descriptor not a Socket

Posted on 1997-08-20
2
1,871 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

Technology Partners: 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

632 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