Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to seperate several messages in a byte buffer

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question How to seperate several messages in a byte buffer

    I send messages through socket. For each read operation, several messags might be queued in a byte buffer at one time. I use a special character '^' which ascii value is 94 as a seperator. The problem is that the message id is integer. When the message id is 94, there is an exception when I try to use the seperator '^' to seperate messages.

    Is there any good way to solve this problem?

    thanks.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: How to seperate several messages in a byte buffer

    How about using more than one character to separate the messages or use a proper serialization library to serialize your objects for you.

    // Json

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: How to seperate several messages in a byte buffer

    Hello perl0101.
    I have moved this thread to - Java Networking

    Why not check the message ID before anything is processed? If it's 94, update it to something else.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Junior Member
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: How to seperate several messages in a byte buffer

    Than you for your suggestions. I will experiment with it today.

  5. #5
    Junior Member
    Join Date
    Jul 2010
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: How to seperate several messages in a byte buffer

    Thank you. It works.

Similar Threads

  1. Error Messages Best Practices
    By Dalek_Supreme in forum Java Theory & Questions
    Replies: 0
    Last Post: April 1st, 2011, 07:22 PM
  2. Switching between frames from a seperate class
    By kurt-hardy in forum AWT / Java Swing
    Replies: 4
    Last Post: February 14th, 2011, 03:19 AM
  3. PLEASE HELP ME with double buffer
    By DouboC in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2011, 04:32 PM
  4. The Bounded Buffer Problem
    By skatescholar in forum Java Theory & Questions
    Replies: 0
    Last Post: April 8th, 2010, 11:22 AM
  5. Replies: 1
    Last Post: April 20th, 2009, 11:17 AM