Hi ,
I am developing client server based application.
After reading the data from the server clients open the thread and starts it in the thread im unable to get data from server when i do it says socket is already closed even the server program is running.
Following is my server THREAD code : which send data to client :
[code]
ServerSocket main = ser.Socket();
while(true){
clientsocket = main.accept();
rdr= new BufferedReader( new InputStreamReader(clientsocket.getInputStream()));
String t="";
String name=rdr.readLine();
System.out.println("Client connected '"+ name +"'");
LstClient.AddClient(name, clientsocket);
ser.clientsNames = LstClient.ClientNames();
objwriter = new ObjectOutputStream(clientsocket.getOutputStream()) ;
objwriter.writeObject(ser.clientsNames);
objwriter.flush();
cam = new Camera();
System.out.println("Turning Camera ON");
cam.cam().open();
System.out.println("Camera live , sending thread on");
Thread.sleep(1000);
wr = new BufferedWriter(new OutputStreamWriter(clientsocket.getOutputStream()) );
wr.write("abc"+'\n');**client thread will read this**
[/code/
following the the client when receives data from server till this line before "TURING CAM ON" and than it donot receive data , it opens a thread and there client need to receive abc from server. Following is the client class :
public Client(String serverIp,int port,String name) throws Exception{ try{ //CloseSocket(); mainSock= new Socket(serverIp, port); writer= new BufferedWriter(new OutputStreamWriter(mainSock.getOutputStream())); writer.write(name); writer.write('\n'); writer.flush(); objin = new ObjectInputStream(mainSock.getInputStream()); ClientsName = (String[])objin.readObject(); System.out.println("Client no.'"+ ClientsName.length ); } catch(Exception ex){ CloseSocket(); throw new Exception("Error : "+ ex.getMessage()); } finally{ if(writer!=null){ writer.close(); } if(objin!=null){ objin.close(); } } } public void ReadVideo(){ try{ if(mainSock!=null){ System.out.println("Starting reading video in 7 sec"); camrdr = new TCameraReader(mainSock); Thread.sleep(7500); System.out.println("Starting reading, thread started"); camrdr.start(); } else { System.out.println("Server not found"); }
and this is the thread clients opens but it says socket is closed.
private ObjectInputStream objin=null; private Socket serverSocket=null; private Webcam cam=null; public TCameraReader(Socket c) { serverSocket = c; } @Override public void run(){ try{ try{ System.out.println("Reading video"); BufferedReader rdr= new BufferedReader( new InputStreamReader(serverSocket.getInputStream())); System.out.println(rdr.readLine()); [B] **here is says socket is closed - here it need to read abc from server** [/B] } catch(Exception ex1){ throw new InterruptedException(ex1.getMessage()); } finally{ try{ if(objin!=null) { objin.close(); } } catch(Exception ex3){ throw new InterruptedException(ex3.getMessage()); } } } catch(InterruptedException ex){ throw new RuntimeException(ex.getMessage()); } }