Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java.net. SocketException: Descriptor not a Socket

Posted on 1997-08-20
2
Medium Priority
?
1,919 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 120 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

671 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