Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

Socket.SendMessage

Sends an UDP data message.

Component Version macOS Windows Linux Server iOS SDK
Socket 3.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "Socket.SendMessage"; SocketID; IP; Port; Text { ; Encoding } )   More

Parameters

Parameter Description Example Flags
SocketID The socket ID received by Socket.Connect 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.
"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: "&$r]
Else
    Set Field [UDP Broadcast::Send Result; "Sent "&$r&" 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"; $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" )]
Set Variable [$r; Value:MBS("PortMidi.SendMessage"; $$stream; 144; 48; 95; $ts )]
Set Variable [$r; Value:MBS("PortMidi.SendMessage"; $$stream; 128; 48; 0; $ts + 500 )]
Set Variable [$r; Value:MBS("PortMidi.SendMessage"; $$stream; 144; 50; 95; $ts + 1000 )]
Set Variable [$r; Value:MBS("PortMidi.SendMessage"; $$stream; 128; 50; 0; $ts + 1500 )]
Set Variable [$r; Value:MBS("PortMidi.SendMessage"; $$stream; 144; 52; 95; $ts + 2000 )]
Set Variable [$r; Value:MBS("PortMidi.SendMessage"; $$stream; 128; 52; 0; $ts + 2500 )]

See also

Release notes

Example Databases

This function checks for a license.

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


Socket.SSL.UsePrivateKeyFile - Socket.SendMessageHex