socket_send (void* data, var size)

Sends data to a connected TCP or UDP network socket.

Parameters:

data - pointer to a buffer that contains the data to be sent.
size - number of bytes to be sent.

Returns:

Number of bytes sent, or 0 when no data could be sent to the socket.

Remarks:

Edition:

 P  LC A7.82

Example:

// Control a GALEP device by sending script commands to its GalepX socket

STRING* strScript = // command script that lets GALEP blink its LEDs
"#include \"gxAPI/gxBasic1.h\"
string s = gxGetCurrentEndDevice();
gxDeviceIdentity(s);
";

TEXT* txtReceive = { flags = SHOW; }

function main()
{
// open a TCP socket on GalepX port 1233 
   if (!socket_connect("localhost",1233,1)) {
      printf("Can't connect to GalepX!");
   } else
   {
// send the script to the socket
      var size = str_len(strScript);
      var sent = socket_send(_chr(strScript),size);
      if (sent) txt_addstring(txtReceive,strScript);
   
// display the response   
      while(1) {
        char input[1000];
        int received = socket_receive(input,1000);
        if (received > 0) {
          input[received] = 0; // add the end mark
          txt_addstring(txtReceive,input);
        }
        wait(1);
     }
  }
}

See also:

send_data, socket_receive, socket_connect

► latest version online