Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem while reading data on java socket

843790Dec 7 2009 — edited Dec 7 2009
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 4 2010
Added on Dec 7 2009
19 comments
327 views