read/write data byte-per-byte to and from a socket

Discussion in 'Java' started by crash.test.dummy, Feb 17, 2006.

  1. the usual data handling that i know in sockets is by using an input
    stream and output stream for reading and writing data, respectively:

    PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
    true);
    BufferedReader in = new BufferedReader(new
    InputStreamReader(clientSocket.getInputStream()));

    1. how do i read data byte-per-byte from a socket?
    2. how do i write data byte-per-byte to a socket?

    thanks.
     
    crash.test.dummy, Feb 17, 2006
    #1
    1. Advertising

  2. crash.test.dummy wrote:
    > the usual data handling that i know in sockets is by using an input
    > stream and output stream for reading and writing data, respectively:
    >
    > PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
    > true);
    > BufferedReader in = new BufferedReader(new
    > InputStreamReader(clientSocket.getInputStream()));
    >
    > 1. how do i read data byte-per-byte from a socket?
    > 2. how do i write data byte-per-byte to a socket?
    >
    > thanks.
    >


    Just use the InputStream and OutputStream that you get from the socket.

    Actually it is interesting that you asked this question this way. There
    are a lot of posts here periodically where people are having trouble
    getting their data moved around. It is almost always caused by using
    some extension of FilterOutputStream/InputStream and available. Use
    InputStream/OutputStream for binary data and buffer it yourself or add a
    BufferedInputStream/OutputStream. For text or string data use
    BufferedReader/Writer. Those will cover 99% of all the I/O you need to do.

    --

    Knute Johnson
    email s/nospam/knute/
     
    Knute Johnson, Feb 17, 2006
    #2
    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. =?Utf-8?B?S01aX3N0YXRl?=

    Quick one - Is SESSION per browser instance or per IP Address?

    =?Utf-8?B?S01aX3N0YXRl?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,912
    gerry
    Apr 10, 2006
  2. Razvan
    Replies:
    1
    Views:
    423
    tony vee
    Sep 10, 2004
  3. jeko

    reading a double var byte per byte

    jeko, Jan 18, 2005, in forum: C Programming
    Replies:
    12
    Views:
    557
  4. Deep
    Replies:
    6
    Views:
    508
    Nick Keighley
    Feb 28, 2007
  5. Replies:
    19
    Views:
    1,328
    Nigel Wade
    Mar 15, 2012
Loading...

Share This Page