Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes ObjectInputStream problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "ObjectInputStream problems "connection reset"" Watch "ObjectInputStream problems "connection reset"" New topic
Author

ObjectInputStream problems "connection reset"

omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
hi all here i have 2 program , one is the server and
the other is the client.
i am having problems with the ObjectInputStream
it must read 5 objects "String" but here it is reading
one or two Objects and then the connection Closes
the Error Message is : connection reset
plz help me with it coz i tried every thing .

/******************************************************************/

import java.io.* ;
import java.net.* ;
public class receive {
public static void main(String[] args) {
try {
Socket s = new Socket("127.0.0.1" , 3000) ;
ObjectInputStream in = new ObjectInputStream(s.getInputStream()) ;
while (true) {
String a = (String)in.readObject() ;
System.out.println("OK " + a ) ;
Thread.sleep(400) ;
}
}
catch (Exception exc) {
System.out.println("Error send "+exc.getMessage()) ;
}
}
}


class send {
public static void main(String[] args) {

try {
ServerSocket ss = new ServerSocket (3000) ;
Socket s = ss.accept() ;

ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream()) ;
//out.flush() ;

for (int i = 0 ; i < 3 ; i++)
out.writeObject("Item :" + i) ;
Thread.sleep(400) ;
}
catch (Exception exc) {
System.out.println("Error send "+exc.getMessage()) ;
}
}
}

class Block implements Serializable{
boolean clicked = false;
String pieceColor ;
String pieceSens ;

Block(String c , String sens) {
clicked = false ;
pieceColor = c ; // pieceColor peut etre Red White nothing
pieceSens = sens ; // sens peut etre up down nothing
}


}
Hern�n Dourisboure
Greenhorn

Joined: Feb 06, 2005
Posts: 1
Hello Omar !!!

I had the same problem. It happens when you run the send application, in the main you invoque the method obj.writeObject three times and then terminate, and this automatically "reset" the connection with the receive application.

You only have three write's , if you put more write's the receive application will continue.

I hope resolve your problem !!

Curna.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ObjectInputStream problems "connection reset"
 
Similar Threads
Server / Client with Threads
socket reset ?
Establishing two-way buffered streams
What is wrong in this code of Serversocket to client message
Help on Serializable