aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes socket reset ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "socket reset ?" Watch "socket reset ?" New topic
Author

socket reset ?

omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
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
}


}
Catalin Merfu
Ranch Hand

Joined: May 26, 2004
Posts: 42
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.


Catalin Merfu<br /><a href="http://www.accendia.com" target="_blank" rel="nofollow">High Performance Java Networking</a>
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
Thx for the help, i'll try it today
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: socket reset ?
 
Similar Threads
ObjectInputStream problems "connection reset"
Synchronization between Remote and GUI
sending objects over a connection.
What is wrong in this code of Serversocket to client message
ObjectStream client-server object sharing problem.