Results 1 to 2 of 2
  1. #1
    noahssite is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default SocketClient is reading line with an end of line byte in it?

    Hello, so far my application has worked perfectly. The server sending a line that is terminated by the '\n' character. The client then read's the line stopping at the '\n' character. Now my issue is that I am sending an image over the connection. At index 43 of the image's byte array there is a "10" which converted to ASCII is the '\n' character. So how can I send the '\n' that is inside the array without having it trigger the end of line?

    Thanks,
    Noah

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,544
    Rep Power
    23

    Default

    That's a problem with using a binary value as the end of record marker. Image files can have any of the 256 possible values for its bytes. You need to come up with a different protocol.
    For example send a lead byte in each transmission that says what type of data follows.
    For text the data would be terminated by a '\n' character
    For binary, the data would be preceded by a length field specifying the number of bytes that follow.

Similar Threads

  1. Java- Writing a file and reading a file line by line
    By Nazneen Ali in forum New To Java
    Replies: 7
    Last Post: 07-20-2011, 07:56 AM
  2. Replies: 1
    Last Post: 02-13-2011, 03:09 PM
  3. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  4. Replies: 9
    Last Post: 04-07-2009, 03:51 AM
  5. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •