Script for telnet server to communicate with J2EE application

Discussion in 'Java' started by Lalit, Aug 29, 2006.

  1. Lalit

    Lalit Guest

    Hi All,
    My Problem:
    I want to interface my J2EE application with data from telnet server. I
    have a device that can send data to a telnet server. Now i want my
    application to fetch that data. My telnet server is on the same machine
    on which my J2EE application is running.
    I also need to write some script which will run on the telnet server to
    take the information from device. But i do not know which scripting
    language to use and how to use...or is there any other solution to this
    problem.

    Can anyone help me in this regard.
     
    Lalit, Aug 29, 2006
    #1
    1. Advertising

  2. Lalit wrote:
    > Hi All,
    > My Problem:
    > I want to interface my J2EE application with data from telnet server. I
    > have a device that can send data to a telnet server. Now i want my
    > application to fetch that data. My telnet server is on the same machine
    > on which my J2EE application is running.
    > I also need to write some script which will run on the telnet server to
    > take the information from device. But i do not know which scripting
    > language to use and how to use...or is there any other solution to this
    > problem.
    >
    > Can anyone help me in this regard.
    >

    Take a look at Javatelnet or search Javaforge for telnet clients written
    in Java and re-use suitable classes to interface your application to a
    telnet server. However, telnet is deprecated these days because it is
    insecure (passwords are sent in plain text), so you might want to use
    ssh instead.

    "Scripting the server". Telnetd and sshd both let you login to the host
    running the server. This gives you a text-only terminal session
    providing command-line access. Hence you can run any script and/or host
    command that the login shell can execute.

    If you go the ssh way you can additionally transfer files and directory
    listings with the protocols used by the scp and sftp utilities.

    HTH


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Aug 29, 2006
    #2
    1. Advertising

  3. Lalit

    Lalit Guest

    Hi Martin,
    Thanks for your valuable comments.

    >"Scripting the server". Telnetd and sshd both let you login to the host
    > running the server. This gives you a text-only terminal session
    > providing command-line access. Hence you can run any script and/or host
    > command that the login shell can execute.


    I just want to do the same. As a telnet Client(In this case a wireless
    barcode scanner) obtain a text only terminal session, get command line
    access and fire a command(which in my case is the barcode number),
    script running on my telnet server should should take this command as a
    data stream and store it in a certain file on the server. Can you guide
    me for writing such a script..
     
    Lalit, Sep 7, 2006
    #3
  4. Lalit wrote:
    > Hi Martin,
    > Thanks for your valuable comments.
    >
    >> "Scripting the server". Telnetd and sshd both let you login to the host
    >> running the server. This gives you a text-only terminal session
    >> providing command-line access. Hence you can run any script and/or host
    >> command that the login shell can execute.

    >
    > I just want to do the same. As a telnet Client(In this case a wireless
    > barcode scanner) obtain a text only terminal session, get command line
    > access and fire a command(which in my case is the barcode number),
    > script running on my telnet server should should take this command as a
    > data stream and store it in a certain file on the server. Can you guide
    > me for writing such a script..
    >

    Not really, with the detail you've supplied. If, say, you just want to
    append the bar code to a file you might use a script like:

    #!/bin/sh
    echo "$1" >>barcode_file

    If the script is called store_barcode, the command

    "store_barcode xxxxyyyy"

    where xxxxyyyy is the bar code which will be appended to barcode_file.
    Of course, you'll need to add error traps, etc.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Sep 7, 2006
    #4
  5. Lalit

    Lalit Guest

    > #!/bin/sh
    > echo "$1" >>barcode_file
    >
    > If the script is called store_barcode, the command
    >
    > "store_barcode xxxxyyyy"
    >
    > where xxxxyyyy is the bar code which will be appended to barcode_file.
    > Of course, you'll need to add error traps, etc.
    >


    Martin,
    That's really an idea i was looking for.
    Is there any way that this script automatically get invoked as the
    Telnet Client login to Server? So that client need not to specify
    store_barcode everytime. Just sending xxxxxyyyy, and the barcode get
    appended to the file.
     
    Lalit, Sep 7, 2006
    #5
  6. On 7 Sep 2006 06:12:22 -0700, Lalit wrote:
    > That's really an idea i was looking for. Is there any way that this
    > script automatically get invoked as the Telnet Client login to
    > Server? So that client need not to specify store_barcode everytime.
    > Just sending xxxxxyyyy, and the barcode get appended to the file.


    Does your device really "log in" to the server using telnet, or does
    it simply use a Socket to connect to a specific port on the server?

    If the former, then write a script like this:

    #!/bin/sh
    cat >> barcode_file

    .... and change the client's login shell to this script.

    If the latter, configure inetd to do "cat >> barcode_file" for
    connections arriving on the specified port. Or perhaps even better,
    have your application listen to that port and read the values itself,
    instead of using the file system as a communications mechanism.

    Regardless of which method you choose, there are synchronization
    issues that need to be addressed if more than one client will be
    logging in at a time.

    What does any of this have to do with J2EE, or Java?

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Sep 7, 2006
    #6
  7. Lalit

    Lalit Guest

    >
    > Does your device really "log in" to the server using telnet, or does
    > it simply use a Socket to connect to a specific port on the server?
    >
    > If the former, then write a script like this:
    >
    > #!/bin/sh
    > cat >> barcode_file
    >
    > ... and change the client's login shell to this script.
    >
    > If the latter, configure inetd to do "cat >> barcode_file" for
    > connections arriving on the specified port. Or perhaps even better,
    > have your application listen to that port and read the values itself,
    > instead of using the file system as a communications mechanism.
    >
    > Regardless of which method you choose, there are synchronization
    > issues that need to be addressed if more than one client will be
    > logging in at a time.
    >
    > What does any of this have to do with J2EE, or Java?
    >


    Ya, device directly login to server....I can not configure the device
    as it is provided by a vendor so it only works with telnet.
    I have to transfer the info send by this device finally to my J2EE
    application server which is on the same machine (on which Telnet Server
    is running) and then pass on to the web client of J2EE application..
    So script is just one part i have to do to integrate this device with
    my application
     
    Lalit, Sep 7, 2006
    #7
  8. Lalit wrote:
    >> #!/bin/sh
    >> echo "$1" >>barcode_file
    >>
    >> If the script is called store_barcode, the command
    >>
    >> "store_barcode xxxxyyyy"
    >>
    >> where xxxxyyyy is the bar code which will be appended to barcode_file.
    >> Of course, you'll need to add error traps, etc.
    >>

    >
    > Martin,
    > That's really an idea i was looking for.
    > Is there any way that this script automatically get invoked as the
    > Telnet Client login to Server? So that client need not to specify
    > store_barcode everytime. Just sending xxxxxyyyy, and the barcode get
    > appended to the file.
    >

    As you were asking about using telnet client classes to allow your Java
    application to talk to a telnet server, I was assuming you'd want to use
    something like the following to login, send one barcode to the telnet
    server and logout again:

    Telnet tnc = new Telnet();

    tnc.login(hostname, username);
    tnc.password(password);
    tnc.sendCommand("store_barcode " + barcode);
    if (tnc.responseOK())
    tnc.logout();
    else
    /* report errors and clean up */

    .... that is, assuming that there is a telnet client class with methods
    corresponding roughly to the actions you'd take if you were manually
    running a telnet session.

    You can get a script to execute automatically with one of the following:
    - if you have root access to the server you could use a captive login
    in place of the shell
    - you can change the bash .profile file in the user to do much the same.

    HOWEVER, once you've done that you can't login to that user normally,
    because doing so will always run your script and then logout. That means
    you'll need a second (normal) login user with full access rights over
    the first user so you can get in for maintenance, e.g. to install a
    modified version of your script, run unit tests or to clean up after a
    failure. But why bother? The method I outlined is easy to do and still
    allows normal logins to the user via a normal telnet session.


    --
    martin@ | Martin Gregorie
    gregorie. | Essex, UK
    org |
     
    Martin Gregorie, Sep 7, 2006
    #8
  9. Lalit

    Lalit Guest

    Thanks Martin,
    Things are moving ahead because of your Idea. I have configured my
    wireless device with a prefix for invoking script. And am able to
    capture data on the server.
    Now the next task is to reflect this data through J2EE app server to
    the Web Client who is waiting for it.
     
    Lalit, Sep 8, 2006
    #9
    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. CoffMan
    Replies:
    0
    Views:
    410
    CoffMan
    Sep 28, 2004
  2. CoffMan
    Replies:
    0
    Views:
    388
    CoffMan
    Sep 30, 2004
  3. vinay
    Replies:
    4
    Views:
    16,170
    vinay
    Jul 28, 2006
  4. Jim Isaacson
    Replies:
    5
    Views:
    606
    Default User
    Nov 5, 2004
  5. Carcarius
    Replies:
    0
    Views:
    297
    Carcarius
    Dec 6, 2007
Loading...

Share This Page