Operating System - OpenVMS
1828664 Members
1479 Online
109984 Solutions
New Discussion

Re: Sending message to a remote telnet device

 
SOLVED
Go to solution
Mushtaq
New Member

Sending message to a remote telnet device

Hi,
This is my first post and my first entry into VMS. I need some help regarding a problem.

I have a program running on a remote machine that reads from a telnet device. I need to connect and send a message every second to this device remotely..
Could you please share some ideas on how I go about doing this?
4 REPLIES 4
Mushtaq
New Member

Re: Sending message to a remote telnet device

I create the telnet device as

$ telnet /create_session/perm/protocol=TELNET 2005 1997

$ SET TERMINAL TNA1997:/perm/nobroadcast/noecho/type_adhead/nowrap/tab/form/SPEED=2400/PARITY=EVEN/PERM
Hoff
Honored Contributor

Re: Sending message to a remote telnet device

I'm guessing that you're likely a Microsoft Windows user and potentially/probably/likely also a Windows programmer, and you're looking for information on IP networking and on device access and C programming on OpenVMS, and (in general) you're comparatively unfamiliar with OpenVMS, probably with how telnet itself works, and (based on inferences from your phrasing) with network client-server communications in general.

Given the dearth of information posted in the question, I'm unfortunately inferring much and may or may not be correctly inferring.

When posting, it's useful to provide a little more detail on the problem and some product versions. For this case, that would be VMS versions, the IP static, maybe the remote client, and how you envision using this network link.

With telnet involving OpenVMS systems, you'll have telnet TN-class devices on both ends of the connection. To establish a telnet device on OpenVMS with TCP/IP Services product, see the CREATE_SESSION command or the DCL telnet command's qualifier /CREATE_SESSION.

From the OpenVMS FAQ:
--

15.2.5 How can I set up reverse telnet (like reverse LAT)?
Though it may seem obvious, Telnet and LAT are quite differentâ with differing capabilities and design goals.
Please see the documentation around the TCP/IP Services for OpenVMS TELNET command CREATE_SESSION. This command is the equivilent of the operations performed in LTLOAD.COM or LAT$SYSTARTUP.COM. There is no TELNET equivilent to the sys$qio[w] control interface for LTDRIVER (as documented in the I/O Userâ s Reference Manual) available, though standard sys$qio[w] calls referencing the created TN device would likely operate as expected.

--

Once you have a telnet TN device, it's a terminal device. Little different than an interactive terminal you've logged into OpenVMS on, too. You can open and read and write it using $qio, language-level file I/O calls, or the DCL command OPEN followed by READ and WRITE and such and (eventually) CLOSE the device.

Now in general, telnet does work for and is designed for use with terminals and printers, and for data usually associated with those devices.

It's not a particularly good choice as a generic interprocess communications protocol, and there can be issues when working with or transferring binary data, for instance.

In recent times, it's less common to see this sort of direct telnet-based programming done; folks are tending to use middleware to deal with this stuff, or are establishing socket connections directly; whether via a known port or via portmapper or via a DNS SRV record or other such.

In recent times, I've only seen or employed telnet and telnet devices with old ASCII-based designs and with exceedingly limited-neworking environments. It's rare. (I have and do use telnet to connect to remote ports for debugging purposes.)

The following socket example is from a Unix box but should work similarly to OpenVMS. This connects to a US NIST server ( time-b.nist.gov) on port 13 and fetches the current time from that server via the Daytime Protocol (RFC-867) mechanisms.

#include
#include
#include
#include
#include
#include
#include

void error(char *msg)
{
perror(msg);
exit(0);
}

int main(int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;

char buffer[256];
if (argc < 3) {
fprintf(stderr,"usage %s hostname port\n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(argv[1]);
if (server == NULL) {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
if (connect(sockfd,(void *)&serv_addr,sizeof(serv_addr)) < 0)
error("ERROR connecting");
n = read(sockfd,buffer,255);
if (n < 0)
error("ERROR reading from socket");
printf("%s\n",buffer);
return 0;
}

$ cc x.c
$ ./a.out time-b.nist.gov 13

55323 10-05-07 04:31:44 50 0 0 498.4 UTC(NIST) *

$



This C code is a variation of the client code available here:

http://www.linuxhowtos.org/C_C++/socket.htm

There is example server code there.

And for the furtherance of your own career in the software industry, please supplant what you were (mis?)taught in school with the following career-advancement advice:

http://www.catb.org/~esr/faqs/smart-questions.html

I'm not kidding here, either. Knowing how to ask a question will advance your career. Surprisingly, most schools don't teach that, either.
Hoff
Honored Contributor
Solution

Re: Sending message to a remote telnet device

Mushtaq
New Member

Re: Sending message to a remote telnet device

Hoff,
Thanks for the help and advice