• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

socket reset ?

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
}


}
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
omar bili
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx for the help, i'll try it today
 
reply
    Bookmark Topic Watch Topic
  • New Topic