writing data form server socket to client socket

Discussion in 'Java' started by greatestmclarenfan, Feb 16, 2006.

  1. I have a program which acts as both a server and a client.
    I have to read data from the the server socket, process the first few
    lines, and then write the remaining data to a client socket. This data
    may contain images.

    Can you tell me the quickest/efficient way of doing this? I would like
    to avoid reading/writing data bit by bit.

    Thanks,
    Swapnil.
     
    greatestmclarenfan, Feb 16, 2006
    #1
    1. Advertising

  2. greatestmclarenfan

    Guest

    use BufferedReader and PrintWriter classes , open 2 connections of each
    , one each to the origin and one to the destination ... cross link both
    of them and ur done ..

    r1 , r2
    w1 , w2

    String line;
    while ( !(line=r1.readLine() ).equals(null) ) {
    w2.write(line);
    }

    // do something

    while ( !(line=r2.readLine() ).equals(null) ) {
    w1.write(line);
    }
     
    , Feb 16, 2006
    #2
    1. Advertising

  3. wrote:
    > use BufferedReader and PrintWriter classes , open 2 connections of each
    > , one each to the origin and one to the destination ... cross link both
    > of them and ur done ..
    >
    > r1 , r2
    > w1 , w2
    >
    > String line;
    > while ( !(line=r1.readLine() ).equals(null) ) {
    > w2.write(line);
    > }
    >
    > // do something
    >
    > while ( !(line=r2.readLine() ).equals(null) ) {
    > w1.write(line);
    > }
    >


    No. That will totally corrupt any binary data like image files.
    You must use InputStream and OutputStream. These have
    read(byte[]) and write(byte[]) methods. Use a byte[] of 1600
    bytes and you should get good performance.
     
    Steve Horsley, Feb 16, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Avizz
    Replies:
    3
    Views:
    13,969
    Andy Fish
    Sep 29, 2003
  2. Max
    Replies:
    5
    Views:
    1,401
    Esmond Pitt
    Feb 29, 2004
  3. -
    Replies:
    2
    Views:
    437
    Alan Krueger
    Jul 29, 2005
  4. Jim Bancroft
    Replies:
    16
    Views:
    1,293
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Sep 13, 2006
  5. David Lee Lambert
    Replies:
    2
    Views:
    1,291
    Martin Gregorie
    Sep 10, 2006
Loading...

Share This Page