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 3 of 3

Thread: MessageSender.java

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation MessageSender.java

    public void sendMessage(String message) throws ProtocolException
    {
    // Announce action
    // This is to help with debugging, it's not required by the protocol

    if (!quiet)
    System.out.println("Sending message => " + message);

    // The following statement shows how the frame sender is invoked.
    // At the moment it just passes the whole message directly to the
    // physical layer. That is, of course, wrong!

    physicalLayer.sendFrame(message);

    // sendMessage needs to split large messages into several smaller
    // segments and encode each segment as a frame in the required
    // format before passing it to sendFrame.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: MessageSender.java

    I fail to see the purpose of your post...do you have a question?

  3. The Following User Says Thank You to copeg For This Useful Post:

    mb201 (November 16th, 2012)

  4. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Re: MessageSender.java

    Quote Originally Posted by copeg View Post
    I fail to see the purpose of your post...do you have a question?

    MessageSender

    The supplied version of sendMessage just passes the whole message string directly to sendFrame without framing or segmentation. As a first step, experiment with running the code supplied to become familiar with the operation of the test harness.


    A next logical step is to implement a partial solution for the simple case of a short message that fits in a single frame and contains no awkward ':' characters. Just set the checksum to '000' for now. For example, if the message is hello the result of this stage will be (hello:000:.). Hint: only one line of Java needs to be edited for this step!


    Implement the checksum field next, e.g. the result should become (hello:532:.). Character values can be obtained using the charAt method (look up the String class in a book or see the online Java API documentation). Java treats individual char values as numbers so they needn't be converted to ints before use in arithmetic calculations.


    Next add code to expand ':' characters to '::'. Don't forget the checksum is calculated before any expansions. E.g. "a:b" would become (a::b:253:.).


    Implement segmentation so that long messages are split into several frames according to the MTU. Don't forget the MTU applies to the whole frame including any expanded ':' characters. The end-of-message flag must be set according to the specification.


    sorry this may be abit confusing but i am not able to do it. Every help is appreciated

Tags for this Thread