Script for telnet server to communicate with J2EE application

L

Lalit

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.
 
M

Martin Gregorie

Lalit said:
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
 
L

Lalit

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..
 
M

Martin Gregorie

Lalit said:
Hi Martin,
Thanks for your valuable comments.


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.
 
L

Lalit

#!/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.
 
G

Gordon Beaton

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
 
L

Lalit

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
 
M

Martin Gregorie

Lalit said:
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.
 
L

Lalit

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top