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 programmer 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 sent = socket_send(_chr(strScript),str_len(strScript));
      if (sent) txt_addstring(txtReceive,strScript);
// receive the response   
      char input[1001];
      while(1) {
        wait(1);
        int received = socket_receive(input,1000);
        if (received) {
// display the response   
          input[received] = 0; // add '0' end mark
          txt_addstring(txtReceive,input);
        }
     }
  }
}

See also:

send_data, socket_receive, socket_connect

► latest version online