Socket.SendMessage
------------------

Sends an UDP data message.

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

MBS( "Socket.SendMessage"; SocketID; IP; Port; Text { ; Encoding } ) 

**MBS**( **"Socket.SendMessage";** /\* Sends an UDP data message. \*/  
**$SocketID**; /\* The socket ID received by [Socket.Connect](SocketConnect.md) function.e.g. $sock \*/   
**$IP**; /\* The target IP or name.e.g. "192.168.2.10" \*/   
**$Port**; /\* The target port to send to.e.g. 9000 \*/   
**$Text**; /\* The text to send.e.g. "Hello World" \*/   
**$Encoding**) /\* Optional; The text encoding for text parameter.   
Default is native.e.g. "UTF8" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| SocketID | The socket ID received by [Socket.Connect](SocketConnect.md) function. | $sock |  |
| IP | The target IP or name. | "192.168.2.10" |  |
| Port | The target port to send to. | 9000 |  |
| Text | The text to send. | "Hello World" |  |
| Encoding | The text encoding for text parameter.    Default is native.   Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the [FAQ](https://www.monkeybreadsoftware.com/filemaker/faq.shtml). | "UTF8" | Optional |

### Result

Returns the number of bytes written or an error message.

### Description

Sends an UDP data message.  
### Examples

Write something:

 MBS ( "Socket.SendMessage"; $sock ; "Hello World" )  
Write something with DOS text encoding:

 MBS ( "Socket.SendMessage"; $sock ; "Umlauts: äöü"; "DOS" )  
Send UDP Package:

 Set Variable \[$r ; Value:MBS ("Socket.SendMessage"; $$sock ; UDP Broadcast::BroadcastAddress ; UDP Broadcast::Port ; UDP Broadcast::Message To Send; "UTF-8")\]  
If \[GetAsNumber($r ) = 0\]  
 Set Field \[UDP Broadcast::Send Result; "Failed to Send: "&amp;$r \]  
Else  
 Set Field \[UDP Broadcast::Send Result; "Sent "&amp;$r &amp;" Bytes."\]  
End If  
Opens stream to Midi device and plays notes with time offsets:

 Set Variable \[$DeviceName ; Value:"Your device name"\]  
If \[$$stream = ""\]  
 Set Variable \[$$stream ; Value:MBS ("[PortMidi.OpenOutput](PortMidiOpenOutput.md)"; $DeviceName ; 100; 10)\]  
 If \[MBS ("ISError")\]  
 Show Custom Dialog \["Failed to open Device"; $$stream \]  
 End If  
End If  
\#Send notes   
Set Variable \[$ts ; Value:MBS ( "[PortMidi.TimeStamp](PortMidiTimeStamp.md)" )\]  
Set Variable \[$r ; Value:MBS ("[PortMidi.SendMessage](PortMidiSendMessage.md)"; $$stream ; 144; 48; 95; $ts )\]  
Set Variable \[$r ; Value:MBS ("[PortMidi.SendMessage](PortMidiSendMessage.md)"; $$stream ; 128; 48; 0; $ts + 500 )\]  
Set Variable \[$r ; Value:MBS ("[PortMidi.SendMessage](PortMidiSendMessage.md)"; $$stream ; 144; 50; 95; $ts + 1000 )\]  
Set Variable \[$r ; Value:MBS ("[PortMidi.SendMessage](PortMidiSendMessage.md)"; $$stream ; 128; 50; 0; $ts + 1500 )\]  
Set Variable \[$r ; Value:MBS ("[PortMidi.SendMessage](PortMidiSendMessage.md)"; $$stream ; 144; 52; 95; $ts + 2000 )\]  
Set Variable \[$r ; Value:MBS ("[PortMidi.SendMessage](PortMidiSendMessage.md)"; $$stream ; 128; 52; 0; $ts + 2500 )\]  
### See also

- [IsError](IsError.md)
- [PortMidi.OpenOutput](PortMidiOpenOutput.md)
- [PortMidi.SendMessage](PortMidiSendMessage.md)
- [PortMidi.TimeStamp](PortMidiTimeStamp.md)
- [Socket.Connect](SocketConnect.md)
- [Socket.SendMessageHex](SocketSendMessageHex.md)

### Release notes

- **Version 14.1**
    - Fixed a problem with [Socket.SendMessageHex](https://www.mbsplugins.eu/SocketSendMessageHex.shtml) function.

### Example Databases

- [Network/UDP/UDP Broadcast](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/UDP/UDP%20Broadcast.shtml#1ScriptAnchor_)
- [Network/UDP/UDP Sender](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/UDP/UDP%20Sender.shtml#1ScriptAnchor_)

This function checks for a license.

Created 18th August 2014 , last changed 23th January 2017

  
[Socket.SSL.UsePrivateKeyFile](SocketSSLUsePrivateKeyFile.md) - [Socket.SendMessageHex](SocketSendMessageHex.md)

[HTML Version](SocketSendMessage.shtml)