Solved

java.net. SocketException: Descriptor not a Socket

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Enhanced For loop vs ForEach Loop 4 54
topping2 challenge 13 55
topping3 challenge 14 48
eclipse formatting 6 38
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now