Important This documentation space contains information about PATROL Agents when deployed in a TrueSight Operations Management environment. If you are a BMC Helix Operations Management user, see PATROL Agent 23.1 for BMC Helix Operations Management.

sopen()


Open a socket channel with a remote host.

Syntax

sopen ( host, port, [IPPreference])

Parameter

Parameter

Definition

host

host name or IP address of remote host

port

port on which to open TCP socket

IPPreference

IP type communication preference, the following values are permitted:

  • IPv4 -- IPv4 only
  • IPv6 -- IPv6 only
  • IPv4,IPv6 --Preference for IPv4 , if none exists then IPv6
  • IPv6,IPv4 -- Preference for IPv6, if none exists then IPv4

Description

The sopen() function opens a TCP socket channel to the specified combination of host and port and provides the access to the socket from within a PSL process. The read(), readln(), write(), get_chan_info(), share(), and close()functions apply to channels that have been opened to sockets in the same manner that file and pipe channels are manipulated via these functions. This function only supports text protocols such as http, telnet, and echo. 

If the IPPreference parameter is not used, then the default connection preference is IPv4 and then IPv6 . 

If the connection is successful, a channel identifier is returned. Otherwise the empty string is returned. Errno is set to E_PSL_FOPEN_CANNOT_CREATE_CHANNEL.

Example

The following PSL statements use sopen() to connect to an SMTP server and determine the maximum message size that the server will accept.

 

#determine maximum acceptable message size
mailhost="ppat5814";
SIZE_supported = 0;
#Open socket channel
chan = sopen (mailhost, "2222","IPv4,IPv6");
if (chan=="") { #Failed to open channel
print ("Could not establish connection to SMTP server.\n");
} else { #Opened channel
#send command to return extension information
write(chan, "EHLO\r\n");
#read first line of reply
ret = readln (chan);
#Did EHLO command succeed?
switch (substr(ret,1,1)) {
case 5: {
print ("SMTP server ". mailhost." does not support EHLO command.\n");
}
case 4: {
print ("Transient failure attempting EHLO on SMTP server ".mailhost.".
Try again later.\n");
}
case 2: { #EHLO succeeded
#Loop until end of EHLO reply, reading lines
while ( ret =~ "-" ) {
if ( ret =~ "SIZE" ) {
size_ret =ret;
SIZE_supported=1;
}
ret = readln (chan);
}
#Did server reply with a SIZE line?
if (SIZE_supported) {
size = nthargf (size_ret, 2);
print ("Maximum message size for SMTP server ".mailhost ." is ".size."
bytes.\n");
} else {
print ("SMTP server ".mailhost." does not support SIZE extension.");
}}
default: {
print ("Failure attempting EHLO command on SMTP server
".mailhost."\n");
}}
#Tell server goodbye
write(chan, "quit");
#Close channel
close(chan);
}

If you run this script from the older Classic console, the following error message might be displayed on the PSL Task bar. You can safely ignore the message. Error Message: " TOO Many Arguments (3) in call to function 'sopen', <=2 arguments expected " To prevent this message from being displayed, upgrade the Classic console to the latest version.

 

 

 

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*