Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: socket closed

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default socket closed

    help, i get socket closed exception for this code:

    package mash.craft.serv.server;
     
    import java.net.*;
    import java.io.*;
     
    import com.mysql.jdbc.ConnectionFeatureNotAvailableException;
     
    public class ServerThread implements Runnable {
        private ServerSocket socket1 = null;
        private Socket socket = null;
     
        public ServerThread(ServerSocket serverSocket) {
    	this.socket1 = serverSocket;
        }
     
        public void run() {
     
    	try {
    		socket = socket1.accept();	//THIS IS LINE 19	
    	    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
    	    BufferedReader in = new BufferedReader(
    				    new InputStreamReader(
    				    socket.getInputStream()));
     
    	    String inputLine, outputLine;
    	    Protocol kkp = new Protocol();
    	    outputLine = kkp.processInput("logged in");
    	    out.println(outputLine);
     
    	    while ((inputLine = in.readLine()) != null) {
    		outputLine = kkp.processInput(inputLine);
    		out.println(outputLine);
    		if (outputLine.equals("stop"))
    		    break;
    	    }
    	    out.close();
    	    in.close();
    	    socket.close();
     
    	} catch (IOException e) {
    	    e.printStackTrace();
    	}
       }
    }
    and the error is in this link:
    22:39:46 [SEVERE] java.net.SocketException: Socket is closed
    22:39:46 [SEVERE] at java.net.ServerSocket.accept(Unknown Source)
    22:39:46 [SEVERE] at mash.craft.serv.server.ServerThread.run(ServerThre ad.
    java:19)


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: socket closed

    Is that unexpected?

    What code is on the other end?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. getting closed server socket in client thread
    By shanalikhan in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 13th, 2013, 06:18 PM
  2. Resource leak: 'in' is never closed..?
    By missm in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 3rd, 2012, 02:01 PM
  3. How to detect if Socket is closed by remote peer?
    By anis_huq in forum Java Networking
    Replies: 1
    Last Post: July 13th, 2012, 09:36 AM
  4. Result set is closed
    By keshav_agrawal89 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 11th, 2011, 08:35 AM
  5. ResultSet is Closed
    By ramayya4u in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: May 24th, 2009, 03:54 AM

Tags for this Thread