A Scripting Language for Web, Linux and Windows

A Scripting Language for Web, Linux and Windows

Example: Working with IPV4/6 stream sockets

The follwing socket functions can be used. Complexer examples with TLS you will find under ssl-client and webserver.

Example: Connect to a hostname/port and send/receive data.

<?v1

hostname 
"myhostname";
socket fsockopen (hostname1000);

if (
socket) {
  print (
"Connected to IP: ".fsockip (socket)." Port: ".fsockport (socket));

  
// Send a string
  
fwrite (socket"TEST");

  
// Try to read 1000 bytes
  // To read line by line use: while (freadln (socket, data)) { ... }
  
data "";
  
bytesRead fread (socketdata1000);
  if (
bytesRead!==false) {
    print (
bytesRead" bytes received.");
    print (
data);
  }
  else {
    print (
"Connection closed or timeout.");
  }

  
// Close socket
  
fclose (socket);
}   

?>

back to Home