Forums Register Login

socket reset ?

+Pie Number of slices to send: Send
Hi ,i have a socket between 2 programs ,one program is sending
5 objects using ObjectInputStream ,and the other is in an endless loop
waiting for objects with the ObjectInputStream
when the 5 objects are sent an exception : socket reset stops the
program ,why is this exception occurs ?
here is the code:

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
}


}
+Pie Number of slices to send: Send
Your server program (send) accepts a client connections, sends 3 String objects to the client and then terminates. The client connection is automatically closed which causes the exception on the client side.

Remove the sleep(400) call in 'receive' and you'll read all the strings.
+Pie Number of slices to send: Send
Thx for the help, i'll try it today
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2797 times.
Similar Threads
ObjectStream client-server object sharing problem.
What is wrong in this code of Serversocket to client message
sending objects over a connection.
ObjectInputStream problems "connection reset"
Synchronization between Remote and GUI
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:45:06.