• Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferedReader and BufferedInputStream  RSS feed

 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone. I'm currently troubleshooting my java program,

I'm trying to link 2 working java programs together.

First program, Client and Server would communicate with each other using PrintWriter and BufferedReader. The program will check whether Client has the correct password to access to the server.

When granted access, second portion of the program will run. This program is a file transfer program. It's using BufferedInputStream and BufferedOutputStream to read and write the stream.

I would like to know whether BufferedReader and BufferedInputStream have any conflict with each other? Would there be any problem if i'm using 1 socket to do all this? In future, I will be transfering more than 1 file.

Please advice. Thanks in advance!
[ October 10, 2007: Message edited by: Adrian Lee ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you run through Sun's Concurrency Tutorial? It has lots of nice examples that may be just what you need.
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stan. I've browsed through the tutorial. But I don't see any examples that uses both BufferedReader and BufferedInputStream. I already have some working examples in hand.

I would like to know whether is it possible to use a socket to transfer both character-input stream and file output stream at different time.

Thanks for your help.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what it means to "transfer both character-input stream and file output stream" Do you want a protocol something like this?
 
Adrian Lee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry if I'm not clear in explaining.

Erm, basically I'm trying to make my client and server program communicate first.

The client will send a password string to the server. The server upon receiving the String, it will check if the client has the correct password. Checking that it's correct, it will proceed to the next step which is the file transfering/downloading part.

I'm just wondering if all this can be done in a single socket without resetting or closing the socket connection?

Thanks for your patience and help in guiding me.
 
Sujith Mahesh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Stan,

When we are reading from a common inputStream how to differentiate between "String" and "raw bytes".
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some options ... the string is fixed length, the string is followed by a delimiter that can't occur in the string, or we put a length out first. I like to make delimited strings with the delimiter first. Then the reader grabs the first character and scans forward for another one just like it.

/header/binary data...

HTTP uses a newline after each header and two newlines between the headers and the body.

You might find it simpler to make the header ASCII instead of Unicode strings. Then you can read everything as bytes and interpret them as you like.
 
Vincent Verdot
Greenhorn
Posts: 5
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!