Results 1 to 7 of 7
  1. #1
    jobud9 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default protocol questions

    I need to make a custom protocol for a project.. How do I make the handler, and the request-er?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,406
    Rep Power
    25

    Default Re: protocol questions

    There are several classes in the java.net package you will need to use to create your own protocol for a URL.
    Can you explain how you plan to use this protocol?

  3. #3
    jobud9 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default Re: protocol questions

    I need an applet to be able to send data over this protocol and get some responses from a jar file.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,406
    Rep Power
    25

    Default Re: protocol questions

    Can you define what you want to do?
    I assume you are looking for a simple way for two programs to communicate over an internet connection.
    List all the types of messages each program can send to the other. Assign an id of some kind and define the contents of the rest of the message that is to be sent.

  5. #5
    jobud9 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default Re: protocol questions

    yes, I am trying to get an applet to talk with a jar, and pass info for a chat log. I need ten functions:

    1. Login {username} {password} - Boolean if user is logged in and int ID response
    2. getMessages {ID}- array of messages response
    3. sendMessage {message} {ID} - Boolean response whether it worked
    4. logout {ID} - Boolean if user is logged out response
    5. ban {ID} {BannedID} - Boolean response if succeeded
    6. unban {ID} {unbandID} - Boolean response if succeeded
    7. mute {ID} {MuteID} - Boolean response if succeeded
    8. unmute {ID} {unmuteID} - Boolean response if succeeded
    9. op {ID} {newopID} - Boolean response if succeeded
    10. de-op {ID} {de-oppedID} - Boolean response if succeeded

    all {} are just variables
    Last edited by jobud9; 12-20-2011 at 11:45 PM.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,406
    Rep Power
    25

    Default Re: protocol questions

    Make a single byte id for each of the functions.
    For the variable length parts of each message you can either send prefix lengths for each of the message's parts or add a delimiter after each part of the message.

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: protocol questions

    Has anyone suggested object serialization? I don't know the core requirements of the 'protocol' but the quickest and simplest way I've always used for network based app to app or client to server communication was object serialization. The idea is this: Write a java object that represents a message. You can even use enumerated types or subclassing or both to allow different types of messages to be used. Include fields for all the commands or data bits you need (strings, booleans, ints, enums, whatever). Then, just open a socket, and send the object through. On the other end, you can read the object just like any other java object and grab whatever properties you need. I wrote a network chess system once that paired players using a centralized server. The communication object was something like this:

    ComMessage
    + type: enum (SIGN_ON, DISCONNECT, MOVE, MESSAGE)
    + username: String
    + source: Point
    + dest: Point
    + message: String

    Based on the enum type, I knew which fields to pay attention to, the rest of the fields would be null. This object held all the data I needed to send chess moves, login commands and usernames, chat client messages, etc...

    Look at the ObjectOutputStream and it's corresponding ObjectInputStream.

    There might be lower overhead protocols, but with efficiency comes effort. I implemented TCP/IP from scratch once in java... argh. Bit shifting is fast, and binary headers are lean, but it was a LOT of work (in java).

Similar Threads

  1. network protocol
    By passer-by in forum Networking
    Replies: 0
    Last Post: 08-09-2011, 08:35 AM
  2. unsupported protocol
    By shiva in forum New To Java
    Replies: 1
    Last Post: 04-09-2009, 09:20 AM
  3. x modem protocol
    By jithan in forum New To Java
    Replies: 0
    Last Post: 08-21-2008, 10:43 AM
  4. New Protocol?
    By lada.r in forum Networking
    Replies: 0
    Last Post: 11-06-2007, 09:13 PM
  5. how to use SIP protocol
    By katie in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 10:22 PM

Posting Permissions

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