Difference between revisions of "FSOCKOPEN()"

From Recital Documentation Wiki
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
{{YLM to do}}
 
 
TCP/IP socket function
 
fp = fsockopen(address as character, port as numeric) as numeric
 
( use fputs(), fgets(), fflush(), fread(), fclose() with this function )
 
 
 
 
==Purpose==
 
==Purpose==
Function to open an existing ASCII text file
+
Function to open a TCP/IP socket
  
  
 
==Syntax==
 
==Syntax==
FOPEN(<expC> [,expN>])
+
FSOCKOPEN(<expC>, <expN>)
  
  
Line 19: Line 12:
  
 
==Description==
 
==Description==
The FOPEN() function opens an existing ASCII text file.  It returns a numeric file pointer when the file is opened successfully, or a -1 if unsuccessful.  The <expC> is the name of the ASCII file to open.  Since the file pointer is required to identify an open file to other file functions, always assign the return value to a memory variable.  The optional <expN> determines the file access mode:
+
The FSOCKOPEN() function opens a TCP/IP socket.  It returns a numeric pointer when the socket is opened successfully, or a -1 if unsuccessful.  The <expC> is the hostname of the server, <expN> is the port number.  Since the pointer is required to identify an open socket to other functions, always assign the return value to a memory variable.   
 
+
 
+
{| class="wikitable"
+
!<expN>||Access Mode
+
|-
+
|||If not specified, read-only
+
|-
+
|0||Read-only
+
|-
+
|1||Write only.  Existing contents are deleted.
+
|-
+
|2||Append.  Text may be added to the end of the existing contents.
+
|-
+
|}
+
  
  
If an error occurs, -1 is returned by the FERROR() function.  The FCLOSE() function is used to close a file which has been opened with FOPEN().
+
The FCLOSE() function is used to close a socket which has been opened with FSOCKOPEN().
  
  
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
use accounts
+
fp=fsockopen("www.server.com",80)
fp=fopen("existing.file")
+
if fp > 0
if ferror()=-1
+
     ...
     dialog box "The file could not be opened."
+
else
+
    string = fgets(fp)
+
    do while not empty(string)
+
        ? string
+
        string = fgets(fp)
+
    enddo
+
    ?
+
 
endif
 
endif
 
fclose(fp)
 
fclose(fp)
if ferror()=-1
 
    dialog box "The file could not be closed."
 
endif 
 
 
</code>
 
</code>
  
Line 63: Line 31:
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
[[Category:ASCII File Access]]
 
[[Category:ASCII File Access Functions]]
 

Latest revision as of 16:05, 1 December 2009

Purpose

Function to open a TCP/IP socket


Syntax

FSOCKOPEN(<expC>, <expN>)


See Also

FCLOSE(), FFLUSH(), FGETS(), FPUTS(), FREAD()


Description

The FSOCKOPEN() function opens a TCP/IP socket. It returns a numeric pointer when the socket is opened successfully, or a -1 if unsuccessful. The <expC> is the hostname of the server, <expN> is the port number. Since the pointer is required to identify an open socket to other functions, always assign the return value to a memory variable.


The FCLOSE() function is used to close a socket which has been opened with FSOCKOPEN().


Example

fp=fsockopen("www.server.com",80)
if fp > 0
    ...
endif
fclose(fp)

Products

Recital, Recital Server