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.

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34

Thread: EOFException

  1. #26
    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: EOFException

    Could that be right?
    What does the trace/debug output show? What order do the events occur in?

    Why does the AllInOne program work?

    2012-07-27 21:13:12.376 - DEBUG: Written: 68
    ....
    2012-07-27 21:13:12.377 - DEBUG: Written: 72

    2012-07-27 21:05:00.738 - DEBUG: Can read: 140
    ...
    2012-07-27 21:05:00.739 - DEBUG: Can read: 0
    The 140 = 68+72.

    Is the available=0 from the same object as the 140?
    Last edited by Norm; July 27th, 2012 at 02:24 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: EOFException

    I honestly have no clue why the AllInOne works and why this one doesnt. I posted the output in the posts above your post. Or is that not what you mean?

    Edit, wait a sec, the only thing that changed is my logger. could that be it?

    edit2, Nope
    Last edited by elamre; July 27th, 2012 at 02:27 PM.

  3. #28
    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: EOFException

    I editted my last post.


    What does the trace/debug output look like for AllInOne?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: EOFException

    That one is one big mess really, since the server and client are in the same console.
    Also yes that is from the same object.
    here is the messy AllInOne:
    ---------------------------------------------------
    Server started
    2012-07-27 21:28:18.101 - SYSTEM: Logger initalized
    2012-07-27 21:28:18.101 - SYSTEM: Logger initalized
    2012-07-27 21:28:18.102 - DEBUG: Sending 3 amount of data
    2012-07-27 21:28:18.102 - DEBUG: Can read: 0
    2012-07-27 21:28:18.102 - DEBUG: Send The following data:
    Name:image.png Size:32888 dir:image.png
    2012-07-27 21:28:18.102 - DEBUG: Amount of data: 3
    2012-07-27 21:28:18.102 - DEBUG: Written bytes: 68
    2012-07-27 21:28:18.102 - DEBUG: Name: image.png
    2012-07-27 21:28:18.102 - DEBUG: Dir: image.png
    2012-07-27 21:28:18.102 - DEBUG: Sending 3 amount of data
    2012-07-27 21:28:18.102 - DEBUG: Send The following data:
    Name:image2.png Size:67145 dir:image2.png
    2012-07-27 21:28:18.102 - DEBUG: Size: 32888
    Name:image.png Size:32888 dir:image.png
    2012-07-27 21:28:18.103 - DEBUG: Written bytes: 72
    2012-07-27 21:28:18.103 - DEBUG: Can read: 72
    2012-07-27 21:28:18.103 - DEBUG: Amount of data: 3
    2012-07-27 21:28:18.103 - DEBUG: Name: image2.png
    2012-07-27 21:28:18.103 - DEBUG: Dir: image2.png
    2012-07-27 21:28:18.103 - DEBUG: Size: 67145
    Name:image2.png Size:67145 dir:image2.png
    ---------------------------------------------------
    2012-07-27 21:28:19.062 - DEBUG: Can read: 0
    2012-07-27 21:28:19.063 - DEBUG: Sending 3 amount of data
    2012-07-27 21:28:19.063 - DEBUG: Send The following data:
    Name:image.png Size:32888 dir:image.png
    2012-07-27 21:28:19.063 - DEBUG: Amount of data: 3
    2012-07-27 21:28:19.063 - DEBUG: Written bytes: 68
    2012-07-27 21:28:19.063 - DEBUG: Name: image.png
    2012-07-27 21:28:19.063 - DEBUG: Dir: image.png
    2012-07-27 21:28:19.063 - DEBUG: Sending 3 amount of data
    2012-07-27 21:28:19.063 - DEBUG: Size: 32888
    Name:image.png Size:32888 dir:image.png
    2012-07-27 21:28:19.063 - DEBUG: Send The following data:
    Name:image2.png Size:67145 dir:image2.png
    2012-07-27 21:28:19.063 - DEBUG: Can read: 72
    2012-07-27 21:28:19.064 - DEBUG: Written bytes: 72
    2012-07-27 21:28:19.064 - DEBUG: Amount of data: 3
    2012-07-27 21:28:19.064 - DEBUG: Name: image2.png
    2012-07-27 21:28:19.064 - DEBUG: Dir: image2.png
    2012-07-27 21:28:19.064 - DEBUG: Size: 67145
    Name:image2.png Size:67145 dir:image2.png
    ---------------------------------------------------
    2012-07-27 21:28:20.063 - DEBUG: Can read: 0
    2012-07-27 21:28:20.064 - DEBUG: Sending 3 amount of data
    2012-07-27 21:28:20.064 - DEBUG: Send The following data:
    Name:image.png Size:32888 dir:image.png
    2012-07-27 21:28:20.064 - DEBUG: Amount of data: 3
    2012-07-27 21:28:20.064 - DEBUG: Written bytes: 68
    2012-07-27 21:28:20.064 - DEBUG: Name: image.png
    2012-07-27 21:28:20.064 - DEBUG: Dir: image.png
    2012-07-27 21:28:20.064 - DEBUG: Size: 32888
    Name:image.png Size:32888 dir:image.png
    2012-07-27 21:28:20.064 - DEBUG: Sending 3 amount of data
    2012-07-27 21:28:20.064 - DEBUG: Can read: 0
    2012-07-27 21:28:20.064 - DEBUG: Send The following data:
    Name:image2.png Size:67145 dir:image2.png
    2012-07-27 21:28:20.064 - DEBUG: Amount of data: 3
    2012-07-27 21:28:20.064 - DEBUG: Written bytes: 72
    2012-07-27 21:28:20.065 - DEBUG: Name: image2.png
    2012-07-27 21:28:20.065 - DEBUG: Dir: image2.png
    2012-07-27 21:28:20.065 - DEBUG: Size: 67145
    Name:image2.png Size:67145 dir:image2.png
    ---------------------------------------------------

  5. #30
    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: EOFException

    Also yes that is from the same object.
    What is that about?

    Is the trace is for AllInOne when there is no problem? It looks like there is a wait between the call to nextInt() and when the data is written, since there is no EOF problem.

    AllInOne worked differently for me from one execution to the next. Sometimes there was an EOF exception and sometimes not.

    Running: java AllInOne

    Server started
    Client0 being started
    Server connection cs=Socket[addr=/127.0.0.1,port=51320,localport=8081]
    CH constru cs=Socket[addr=/127.0.0.1,port=51320,localport=8081]
    FSR - exiting constructor socket=Socket[addr=/127.0.0.1,port=51320,localport=8081]
    Client constru socket=Socket[addr=/127.0.0.1,port=8081,localport=51320]
    FSR - exiting constructor socket=Socket[addr=/127.0.0.1,port=8081,localport=51320]
    Client0 started
    FSR entering sendFile name=images/RedCar.png
    FI exiting write size=86
    FSR exiting sendFile name=images/RedCar.png
    FSR entering sendFile name=images/BlueCar.png
    FI exiting write size=90
    FSR exiting sendFile name=images/BlueCar.png
    closed java.net.SocketInputStream@1e1153a
    closed java.net.SocketOutputStream@38c403
    closed socket=Socket[addr=/127.0.0.1,port=51320,localport=8081]
    CH run exiting
    0 Client run entered <<<<<<<<<<<
    FSR entering receiveFile
    FI read dis=java.io.DataInputStream@2b16b8,avail=176
    Client1 being started
    FI read dA=3
    FI read choice=1
    FI read name=RedCar.png
    FI read choice=2
    FI read dir=images\RedCar.png
    FI read choice=3
    Server connection cs=Socket[addr=/127.0.0.1,port=51321,localport=8081]
    FI read size=1137
    CH constru cs=Socket[addr=/127.0.0.1,port=51321,localport=8081]
    Client constru socket=Socket[addr=/127.0.0.1,port=8081,localport=51321]
    FSR - exiting constructor socket=Socket[addr=/127.0.0.1,port=8081,localport=51321]
    FSR - exiting constructor socket=Socket[addr=/127.0.0.1,port=51321,localport=8081]
    Name:RedCar.png Size:1137 dir:images\RedCar.png
    FSR exiting receiveFile

    FSR entering receiveFile
    FI read dis=java.io.DataInputStream@18a8bfa,avail=0
    0 Client run ex
    java.io.EOFException
    at java.io.DataInputStream.readInt(Unknown Source)
    at AllInOne$FileInfo.read(AllInOne.java:154)
    at AllInOne$FileSendRecieve.recieveFile(AllInOne.java :291)
    at AllInOne$Client.run(AllInOne.java:110)
    Client1 started
    at java.lang.Thread.run(Unknown Source)
    0 Client run exited <<<<<<<<<<<
    FSR entering sendFile name=images/RedCar.png
    FI exiting write size=86
    FSR exiting sendFile name=images/RedCar.png
    FSR entering sendFile name=images/BlueCar.png
    FI exiting write size=90
    FSR exiting sendFile name=images/BlueCar.png
    closed java.net.SocketInputStream@177c977
    closed java.net.SocketOutputStream@14bcb5c
    closed socket=Socket[addr=/127.0.0.1,port=51321,localport=8081]
    CH run exiting
    1 Client run entered <<<<<<<<<<<
    FSR entering receiveFile
    FI read dis=java.io.DataInputStream@1144026,avail=176
    FI read dA=3
    FI read choice=1
    FI read name=RedCar.png
    FI read choice=2
    FI read dir=images\RedCar.png
    FI read choice=3
    FI read size=1137
    Name:RedCar.png Size:1137 dir:images\RedCar.png
    FSR exiting receiveFile
    FSR entering receiveFile
    FI read dis=java.io.DataInputStream@7fbad7,avail=0
    1 Client run ex
    java.io.EOFException
    at java.io.DataInputStream.readInt(Unknown Source)
    at AllInOne$FileInfo.read(AllInOne.java:154)
    at AllInOne$FileSendRecieve.recieveFile(AllInOne.java :291)
    at AllInOne$Client.run(AllInOne.java:110)
    at java.lang.Thread.run(Unknown Source)
    1 Client run exited <<<<<<<<<<<
    main exiting

    0 error(s)
    Notice:
    FI exiting write size=86
    FI exiting write size=90
    FI read dis=java.io.DataInputStream@1144026,avail=176
    Last edited by Norm; July 27th, 2012 at 02:45 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: EOFException

    Yeah i know, sometimes it works, and sometimes it doesn't. this makes it very hard for me to find the problem and fix it.

    Also i don't know what that is about. I gave a possible explanation on that in my previous post. Anything else i can't seem to think of.

  7. #32
    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: EOFException

    Try changing the code so it reads from the same class object. The posted code gets a new class objects every time it does a read.
    Last edited by Norm; July 27th, 2012 at 03:17 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    elamre (July 27th, 2012)

  9. #33
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: EOFException

    What is this? is this real life? now it works. But why?

    I changed my FileSendRecieve to the following:
    public class FileSendRecieve {
    	Socket socket;
    	OutputStream socketOut;
    	InputStream socketIn;
    	DataInputStream dataIn;
    	DataOutputStream dataOut;
    	FileInfo fileinf = new FileInfo();
     
    	public FileSendRecieve(Socket socket) {
    		try {
    			socketOut = socket.getOutputStream();
    			socketIn = socket.getInputStream();
    			dataOut = SocketUtil.wrapOutputStream(socket);
    			dataIn = SocketUtil.wrapInputStream(socket);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		this.socket = socket;
    	}
     
    	public void sendFile(String name, String directory) throws IOException {
    		File file = new File(name);
    		fileinf.setFile(file);
    		fileinf.write(dataOut);
    	}
     
    	public void recieveFile() throws IOException {
    		fileinf.read(dataIn);
    		fileinf.print();
    	}
     
    	public void stop() {
    		SocketUtil.close(socketIn);
    		SocketUtil.close(socketOut);
    		SocketUtil.close(socket);
    	}
    }
    So im not making new objects anymore. Maybe better for performance as well.

    Also something TOTALLY different, what is the difference between the code=java tags and the highlight=java?
    Last edited by elamre; July 27th, 2012 at 03:23 PM.

  10. #34
    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: EOFException

    I think having two BufferedInputStreams in parallel was confusing the system. Which one would be keeping track of what bytes had been read? Having only one removes the confusion.

    [code = java]
    Maybe the spaces around the = confuses the forum's code.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. EOFException on sending object
    By treshr in forum Java Networking
    Replies: 1
    Last Post: December 9th, 2011, 01:20 PM
  2. java.io.EOFException when sending object through socket
    By treshr in forum Java Networking
    Replies: 2
    Last Post: November 8th, 2011, 06:13 AM