there is some glitch in read( )..please help me sort out the problem
**server**
import java.net.*;
import java.io.*;
class BufferedInputServer
{
public static void main(String args[])
{
BufferedInputStream bis;
BufferedOutputStream bos;
try
{
ServerSocket ss=new ServerSocket(1234);
Socket s=null;
while (true)
{
System.out.println("server waiting");
s=ss.accept();
try
{
bis=new BufferedInputStream(s.getInputStream());
bos=new BufferedOutputStream(s.getOutputStream());
try
{
int c=0;
while (true)
{
c=bis.read();
if(c==-1||c=='\n')
break;
System.out.print((char)c);
}
}
catch(Exception e)
{
System.out.println("Exception in Reading and the exception is\t"+e);
}
System.out.println("After reading");
String str="message received mate";
byte b[]=str.getBytes();
bos.write(b);
bos.flush();
s.close();
}
catch(Exception e)
{
System.out.println("exception in loop try catch block and the exception is\t"+e);
}
finally
{
try
{
if(s!=null) s.close();
}
catch(Exception e)
{
System.out.println("inside finally and the exception is\t"+e);
}
}
}
}
catch(Exception e)
{
System.out.println("exception outside the loop try catch"+e);
}
}
}
/**client**/
import java.net.*;
import java.io.*;
class BufferedInputSocket{
public static void main(String args[])
{
BufferedInputStream bis;
BufferedOutputStream bos;
Socket s=null;
try
{
s=new Socket("127.0.0.1",1234);
String str="im sending u a message";
byte b[]=str.getBytes();
bos=new BufferedOutputStream(s.getOutputStream());
bis=new BufferedInputStream(s.getInputStream());
bos.write(b);
bos.flush();
try{
int c=0;
while (true)
{
if(c==-1||c=='\n')
break;
System.out.print((char)c);
}
}
catch(Exception e)
{
System.out.println("Exception in Reading\t"+e);
}
}
catch(Exception e)
{
System.out.println("exception in outer try catch block and the exception is\t"+e);
}
finally
{
try
{
if(s!=null) s.close();
}
catch(Exception e)
{
System.out.println("inside finally and the exception is\t"+e);
}
}
}
}

