Java tcp packet stream

Is it possible to read a socket inputstream character by character? ObjectInputStream etc are based on a newline character. I would like to be able to read all the characters as they come in. Is this possible?

I have looked at the pipedInputStream/pipedoutputstream but I don't think that-that is quite what I am looking for (I can't figure out how to make pipedstream work)

Thanks,

John

[414 byte] By [john8675309a] at [2007-11-26 13:05:58]
# 1

> Is it possible to read a socket inputstream character

> by character?

Yes, assuming you mean byte by bye

> ObjectInputStream etc are based on a

> newline character.

No.

> I would like to be able to read

> all the characters as they come in. Is this

> possible?

int b = socket.getInputStream.read();

> I have looked at the

> pipedInputStream/pipedoutputstream but I don't think

> that-that is quite what I am looking for (I can't

> figure out how to make pipedstream work)

This has nothing to do with TCP.

ejpa at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...
# 2

public static void main(String[] args) {

// TODO code application logic here

try {

ServerSocket s = new ServerSocket(1234);

Socket sock = s.accept();

while(true) {

int b = sock.getInputStream().read();

System.out.println(b);

}

} catch (Exception e) {e.printStackTrace();}

}

the above code still expects an enter to be pressed before b will be displayed. How can I read the stream byte by byte as they come in?

--John

john8675309a at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...
# 3
This code is reading a socket. Where is the enter key on a socket?I suppose you mean that the client is sending data read from System.in.in which case the problem is at the client end and nothing to do with TCP.
ejpa at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...
# 4
Right I just type telnet 127.0.0.1 1234 then type chars I would like those chars to appear on the server as there typed. I am looking for a specific character in the stream.--John
john8675309a at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...
# 5
Can telnet be configured to send a character at a time rather than a line at a time? I have no information on this.
ejpa at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...
# 6
I notice while reading the man page it talks about character at a time processing. Do you know if there is a way to force the server to set this mode?--John
john8675309a at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...
# 7
It's not the server, it's the telnet client. I have no information.
ejpa at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...
# 8
I completly understand, but how can cisco read in realtime when I hit the ? for example ip ? will automatically display the help screen. That is all I want to do. Is it possible?Thanks for all the quick responses. This is just for a hobby but it's getting fun!--John
john8675309a at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...
# 9
Cisco probably has a real telnet server that negotiates a char-by-char mode with the telnet client. You can do that with your code, you just have to look at about a dozen RFCs ;-)
ejpa at 2007-7-7 17:14:01 > top of Java-index,Core,Core APIs...