Socket.SetDataAvailableHandler
------------------------------

Sets the data available handler for this socket.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Socket](component_Socket.md) | [3.1](newinversion31.md) | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes |

MBS( "Socket.SetDataAvailableHandler"; SocketID; FileName; ScriptName ) 

**MBS**( **"Socket.SetDataAvailableHandler";** /\* Sets the data available handler for this socket. \*/  
**$SocketID**; /\* The socket ID received by [Socket.Connect](SocketConnect.md) function.e.g. $sock \*/   
**$FileName**; /\* The name of the FileMaker File that contains the scripte.g. "MyDatabase.fp7" \*/   
**$ScriptName**) /\* The name of the script to rune.g. "DataAvailable" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| SocketID | The socket ID received by [Socket.Connect](SocketConnect.md) function. | $sock |
| FileName | The name of the FileMaker File that contains the script | "MyDatabase.fp7" |
| ScriptName | The name of the script to run | "DataAvailable" |

### Result

Returns OK or error message.

### Description

Sets the data available handler for this socket.  
When new data arrives, this script is called, so you can call [Socket.Read](SocketRead.md) function.  
Be aware that script may be called when just a few bytes are in the read buffer. So the data message you wait for may only be available partly. In that case, please read available bytes, check if whole packet/message arrived and if not, store read data for later and wait for next script call.  
  
The script parameter is the ID of the socket. You can associate additional values with [Socket.SetTag](SocketSetTag.md) function to the socket and use them in the script triggered.  
  
  
With plugin version 6.0 or newer the script name can be a script ID number. In that case the plugin queries the script name for the given script ID. This allows to call scripts by ID and avoid problems if scripts are later renamed.  
  
Notice: FileMaker 19.2 adds a fmplugin extended privileges. If you have such an extended privileges to allow the plugin to trigger scripts, you need to grant permissions for it. If such a privilege is not defined, the plugin is allowed to trigger scripts. See FileMaker product documentation for details.  
### Examples

Set script to be triggered if data is available:

 Set Variable \[$r ; Value:MBS ("Socket.SetDataAvailableHandler"; $$sock ; Get(FileName); "ReadMessage")\]  
### See also

- [PortMidi.SetDataAvailableHandler](PortMidiSetDataAvailableHandler.md)
- [SerialPort.SetDataAvailableHandler](SerialPortSetDataAvailableHandler.md)
- [Socket.AcceptNewConnection](SocketAcceptNewConnection.md)
- [Socket.ClearDataAvailableHandler](SocketClearDataAvailableHandler.md)
- [Socket.Connect](SocketConnect.md)
- [Socket.NewUDPSocket](SocketNewUDPSocket.md)
- [Socket.Read](SocketRead.md)
- [Socket.SetDataAvailableEvaluate](SocketSetDataAvailableEvaluate.md)
- [Socket.SetDataAvailableURL](SocketSetDataAvailableURL.md)
- [Socket.SetTag](SocketSetTag.md)

### Example Databases

- [Network/HTTP Server hosted](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/HTTP%20Server%20hosted.shtml#3ScriptAnchor_)
- [Network/HTTP Server local](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/HTTP%20Server%20local.shtml#3ScriptAnchor_)
- [Network/Socket Test/Socket Test](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/Socket%20Test/Socket%20Test.shtml#3ScriptAnchor_)
- [Network/TCP Send and Receive/TCP Receiver](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/TCP%20Send%20and%20Receive/TCP%20Receiver.shtml#3ScriptAnchor_)
- [Network/TCP Send and Receive/TCP Sender](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/TCP%20Send%20and%20Receive/TCP%20Sender.shtml#1ScriptAnchor_)
- [Network/UDP/UDP Broadcast](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/UDP/UDP%20Broadcast.shtml#2ScriptAnchor_)
- [Network/UDP/UDP Receiver](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/UDP/UDP%20Receiver.shtml#1ScriptAnchor_)

This function checks for a license.

Created 18th August 2014 , last changed 27th March 2019

  
[Socket.SetDataAvailableEvaluate](SocketSetDataAvailableEvaluate.md) - [Socket.SetDataAvailableURL](SocketSetDataAvailableURL.md)

[HTML Version](SocketSetDataAvailableHandler.shtml)