SendWithLineEnd (Socket function)

From m204wiki
Jump to navigation Jump to search

Send a string plus line end character (Socket class)


This method sends a string and an untranslated line-end string over a Janus Sockets connection. The line-end string may be set on the port definition via the Set method or as an argument on the SendWithLineEnd function.

The SendWithLineEnd function, which may be invoked with a Call statement, has an effect similar to $Sock_SendLn.

Syntax

[%number =] socket:SendWithLineEnd( string, [[Options=] string])

Syntax terms

%number If specified, this is a numeric variable to contain the returned indicator of success of the function. The return value is either of these:
0 The function completed successfully.
-1 The socket is not open, and ONRESET CONTINUE is in effect for the socket.
socket A variable or an expression that is a reference to a Socket object.
string The string to send.
Options This optional, name allowed, argument is an option string that may contain any of the following:
BINARY Regardless of whether the BINARY or CHAR parameter is in effect for the socket's port, data is not translated when sent. The argument can be the result of a previous translation using the TranOut
CHAR Regardless of whether the BINARY or CHAR parameter is in effect for the socket's port, data is translated when sent. The translation is specified by the output table defined by the socket's XTAB paramete
FIN After string is sent, no more data will be sent on the socket. This transmits the FIN indication to the remote partner. Note that when FIN is sent, print capturing is automatically turned OFF for the socket.
PUSH Ensures that the data being sent on the socket is immediately sent to the receiver. Normally, data to be sent is buffered and may not be sent immediately.

Using PUSH is not necessary if:

  • You are specifying FIN, since a push operation is implied by FIN.
  • You are alternating sends and receives on a socket, since receive-processing methods (Receive and ReceiveAndParse) always do a push before receiving.
LINEND hexstr The line-end string to send. The string whose hexadecimal representation is hexstr is used rather than the current LINEND parameter setting in effect for the socket. For example:

%sock:SendWithLineEnd('GO', 'LINEND 07')

Usage notes

  • Whether it's set on the port definition, via the Set method, or as an argument on the SendWithLineEnd function, LINEND must not be NONE when using SendWithLineEnd.

Examples

The following example uses a combination of Send and SendWithLineEnd.

... %domain = 'www.sirius-software.com' %page = 'main.html' %socket is Object Socket %socket = New('TEST', %domain) %socket:Set('LINEND', '0D0A') %socket:Send('GET /') %rc = %socket:Send(%page) %rc = %socket:SendWithLineEnd(' HTTP/1.0') %rc = %socket:SendWithLineEnd() ...

In this example, the Set method specifies a line-end string of hexadecimal '0D0A'. Then, lines are sent for which the protocol does not require line-end delimiters: the "GET," and the HTML page defined in %page. Then the SendWithLineEnd function sends the HTTP specification with a line-delimiter.

This example highlights the fact that the programmer needs to know the requirements of the communication protocol before they know the appropriate method to use to send strings to the socket.