Friday, 9 August 2013

Reading and using Input from client

Reading and using Input from client

I have written a small program that has the following piece of code
static Socket client;
public static void run()
{
try {
ServerSocket svrSocket = new ServerSocket(4034);
try{
client = svrSocket.accept();
DataOutputStream outToServer = new
DataOutputStream(client.getOutputStream());
BufferedReader in = new BufferedReader(new
InputStreamReader(client.getInputStream()));
//String inputLine, outputLine;
outToServer.writeBytes("GET\n");
outToServer.flush();
if(in.readLine().equals("GET"))
{
System.out.println("working");
}
else
{
System.out.println("not running");
}
in.close();
outToServer.close();
client.close();
svrSocket.close();
}catch(IOException e){}
svrSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(-1);
}
}
As you can see I write GET to the server and a little later I use a if
statement to see If I have written GET to the Server. I want the response
working, but I get the response not running. Why would this be and how can
I fix it?
Thank you

No comments:

Post a Comment