This is an old revision of the document!
WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0
Open an internet socket connection with optional timeout
Attempts to create a socket to a remote host using the protocol specified, and return the file handle for future operations. By default a TCP/IP connection will be initiated. If a UDP connection is required prefix the host name with udp:// (lower case). The socket will be opened in blocking mode.
host: Host name or IP address of server to connect to
port: Port number
timeout: Connection timeout in seconds, optional (if not specified the system wide setting in uphp.ini will be used).
Upon success it returns a file handle which may be used together with the other file functions that require a handle such as fgets(), fwrite(), fclose() and feof()
If the attempt to open the connection fails it will return 0
Create a connection to www.example.com and display the response:
<? $fp=fsockopen("www.example.com",80,30); if (!$fp) { print("Socket open failed"); } else { $out="GET / HTTP/1.1\r\n"; $out.="Host: www.example.com\r\n"; $out.="Connection: Close\r\n\r\n"; fwrite($fp,$out); while (!feof($fp)) { echo(fgets($fp,128)); } fclose($fp); } ?>
fseropen() - Open the serial port at the specified baud rate with optional parameters
f485open() - Open the RS-485 port as a stream
fopen() - Open a file for reading or writing
fclose() - Close a file, stream or socket
feof() - Test if no more data is available in a file or stream
fgets() - Return a single line from a file or stream, with optional size limit
fread() - Return bytes from a file or stream
fwrite() - Write data to a file or stream