Re: a new java to c socket question

Discussion in 'Java' started by xarax, Jul 22, 2003.

  1. xarax

    xarax Guest

    "Brad Chambers" <> wrote in message news:<ugUSa.3254$>...
    > I'm working with code that passes a structure over a socket connection
    > between a c client and server. I have an application where I need the
    > client-side to be implemented in java. Is there an easy way to create and
    > send a structure that will require no modifications to my server? I haven't
    > worked much with java, especially sockets, and am just beginning to explore
    > this option. Basically all the structure contains are two fields, one
    > representing a type (to determine whether the command is even valid, and
    > then to determine an appropriate action) and one with some parameters for
    > the command.
    > Thanks,
    > Brad

    I had to do a complex variation of this scenario. Java on one
    side talking with C on the other side. I created a custom program
    generator ( that would process
    my own XML specifications for message packets. The generator
    would spit out Java source files and C header/source files that
    mapped the various message packet types.

    For a particular message packet, the Java class used a
    java.nio.ByteBuffer to arrange the various fields. The getter/setter
    methods would handle the conversions as needed. The corresponding
    C files also had a struct to map the expected ByteBuffer, and
    getter/setter functions for dealing with the field values.

    Thus, my "server" code only uses the header files and the
    getter/setter function calls to deal with the fields by
    name. Same goes for the "client" code on the Java side. The
    main logic of either side never sees the raw byte stream. This
    also helps insulate the main code from issues like Endian byte
    ordering (handled automatically by ByteBuffer) and alignment

    Adding a field to message packet takes only a few seconds
    (I also have a generated GUI front-end for managing the XML)
    to regenerate the source files. Then I recompile both sides.
    Just takes a few keystrokes, the program generator ensures
    that both sides are always in-synch.

    2 cents worth. Your mileage may vary.
    xarax, Jul 22, 2003
    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. Laszlo Nagy
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Steve Holden
    Feb 1, 2009
  5. Steve Holden

Share This Page