Program enters infinite loop.

this is the first program i'm writing with sockets and is also a step towards making a chat application. my problem is that the program enters infinite loop.

package server;

import java.net.*;

import java.io.*;

class Server

{

publicstaticvoid main(String[] args)throws Exception

{

ServerSocket ss =new ServerSocket(9090);

Socket soc = ss.accept();

BufferedReader in =new BufferedReader(new InputStreamReader(soc.getInputStream()));

String str = in.readLine();

while(str!="")

{

System.out.println(str);

str = in.readLine();

}

soc.close();

ss.close();

}

}

this was the server - a seperate application. below is a part of the client - a seperate application

privatevoid jButton1ActionPerformed(java.awt.event.ActionEvent evt){

try

{

InetAddress ip = InetAddress.getByName("127.0.0.1");

Socket soc =new Socket(ip,9090);

PrintWriter out =new PrintWriter(new BufferedWriter(new OutputStreamWriter(soc.getOutputStream())),true);

str_out = jTextArea2.getText();

while(str_out!="")

{

out.println(str_out);

str_out = jTextArea2.getText();

}

soc.close();

}

catch(Exception e)

{

System.out.println("Error sending message");

}

}

privatevoid jButton2ActionPerformed(java.awt.event.ActionEvent evt){

str_out ="";

jTextArea2.setText(str_out);

}

when i press button send (jButton1) the text from the text area jTextArea2 is supposed to go to the server and then the server should display it in its out put screen. i tried sending hello and the server went on printing hello continously.

pleas help.

[3112 byte] By [kothari_neerava] at [2007-11-26 18:04:04]
# 1

>String str = in.readLine();

> while(str!="")

>{

>System.out.println(str);

>str = in.readLine();

> }

You need to test for (str != null) above too, or instead of str != "".

ejpa at 2007-7-9 5:34:22 > top of Java-index,Core,Core APIs...
# 2
while(str!="")makes the program enter infinite loop and it goes on printing 'null'. whereas,while(str!=null)runs fine!thankyou.
kothari_neerava at 2007-7-9 5:34:22 > top of Java-index,Core,Core APIs...