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);

}

}

}

}

[2564 byte] By [socketsa] at [2007-11-27 8:26:07]
# 1
There almost certainly isn't a glitch in read(). You haven't presented any evidence, or even a description of what you think is wrong. Try again, and use [code] tags
georgemca at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...
# 2
im printing a message in the server side...but the message frm client side is not appearing in the server side
socketsa at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...
# 3
Oh, well it must be a glitch in read(), then. File a bug report with Sun
georgemca at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...
# 4
It couldn't possibly be that you coded something incorrectly could it?
puckstopper31a at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...
# 5

i checked it 100 times..and i wrote the same code using deifferent streams...buffered reader and writer...dataoutputstreams and datainputstreams ,objectinput and objectoutputstreams..im encountering the same problem..can anybody take the pain of compiling the program and sort out the problem..ill be more than grateful

socketsa at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...
# 6
What I can tell you definatively is that I would not approach the problem the way you have.PS.
puckstopper31a at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...
# 7
> im printing a message in the server side...but the> message frm client side is not appearing in the> server sideYes it is. I just ran it. I note, though, that the client creates an input stream it never uses
georgemca at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...
# 8
i've just started learning sockets and i felt that this is the basic caose in communication
socketsa at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...
# 9

hey.. i think the problem is here.

int c=0;

while (true)

{

if(c==-1||c=='\n')

break;

System.out.print((char)c);

}

boneysekha at 2007-7-12 20:15:24 > top of Java-index,Java Essentials,Java Programming...