Why is this code not working?
I have written the program below but somehow after read the input stream the server doesnot process the outputstream... it gets sort of stuck....
I tried Buffered Reader and InputStream for reading input from program. While using 'is' (InputStream) gets me to line that contains
System.out.println("I am here") , using BufferedReader is not taking me beyond the while loop
import java.io.*;
import java.util.*;
import java.net.*;
public class WhoisServer {
static int port=43;
static Socket s=new Socket("localhost",43);;
public static void main(
String args[])
{
try {
ServerSocket soc=new ServerSocket(port);
InputStream is;
Reader rd;
BufferedReader br=null;
OutputStream os;
OutputStreamWriter out=null;
BufferedWriter bw;
String inquiry="";
String output1="Hello";
String output2="There";
String output3="I";
String output4="am";
String output5="Just Testing";
String output6="Bye";
while(s!=null){
s=soc.accept();
os=s.getOutputStream();
System.out.println(s);
is= s.getInputStream(); int letter=0;
br=new BufferedReader(new InputStreamReader(is));
/*while(letter!='\r'){ letter=is.read();
inquiry=inquiry+(char)letter; }
*/
while(inquiry!=null){ inquiry=br.readLine();
if(inquiry!=null)
System.out.println(inquiry);
}
out= new OutputStreamWriter(os);
out.write("Welcome to host");
System.out.println("I am here");
out.write(output1);
out.flush();
}
//System.out.println(url);
s.close();
br.close();
out.close();
} catch (Exception ioe) {
String mess=""+ioe;
if(mess.indexOf("JVM_Bind")!=-1)
System.out.println("Server Already Running at : " +port );
else
System.out.println("Server Whois : " + ioe);
}
}
}
You may see the sample application using this server here
Whois Server at this very IO stream forum Thank you in advance
Maki Jav
[ November 08, 2003: Message edited by: Maki Jav ]