problem while reading data on java socket
843790Dec 7 2009 — edited Dec 7 2009Hi All,
I am in big problem based on java socket programming. I run my application and start a ServerSocket on 10000(suppose) port no.As soon as request is coming i create a new thread with Socket assigned to it and process the request. Now i got the response and written on same Socket(Listen to ServerSocket on 10000 port). Now what i want to read the response written earlier on Socket.The written response i print on SOP it is visible. But when i establish InputStream and try to read the data it gives me -1 means no data is available. But i have seen the SOP and data is written to socket. How can solve the problem. I have tried after close the Socket as well as not close the socket.
Please help me out on this.see below code
<CODE>
void upperClassMethod() {
istener = new ServerSocket(port);
while(true) {
clientSocket = listener.accept();
}
doComms conn_c= new doComms(clientSocket);
Thread t = new Thread(conn_c);
t.start();
}
//doComms is a inner class of upper level class
class doComms implements Runnable {
private Socket server;
doComms(Socket server) {
//pp = server;
this.server=server;
//server=server1;
}
void processResponse() {
try {
BufferedInputStream in = new BufferedInputStream (clientSocket.getInputStream());
byte [] inBuff = new byte [4096] ;
int len = in.read (inBuff, 0, inBuff.length) ;
String output = new String (inBuff) ;
System.out.println("the output is :::: "+output);
} catch(Exception e) {
e.printStackTrace();
}
}
</CODE>
in processResponse() method i am not able to get output. Plz help me guys.....
Thanks in advance for ant assistance
Regards,
Pradeep