Socket.WriteHex
---------------

Writes text to the socket.

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

MBS( "Socket.WriteHex"; SocketID; Text ) 

**MBS**( **"Socket.WriteHex";** /\* Writes text to the socket. \*/  
**$SocketID**; /\* The socket ID received by [Socket.Connect](SocketConnect.md) function.e.g. $sock \*/   
**$Text**) /\* The text to send in hex encoding.e.g. "48656C6C6F" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| SocketID | The socket ID received by [Socket.Connect](SocketConnect.md) function. | $sock |
| Text | The text to send in hex encoding. | "48656C6C6F" |

### Result

Returns the number of bytes written or an error message.

### Description

Writes text to the socket.  
You pass the text hex encoded. For example for "Hello" you pass "48656C6C6F".  
  
Result is -1 if socket can't write. See [Socket.LastError](SocketLastError.md) for error code.  
Changed in v10.4 to return error if socket is closed or disconnected instead of -1.  
### Examples

Write some text:

 MBS ( "Socket.WriteHex"; $sock ; "48656C6C6F" )  
Send some command:

 MBS ( "Socket.WriteHex"; $sock ; "02064F07A203" )  
  
// sends  
// &lt;STX&gt;&lt;6&gt;&lt;CMD\_ON&gt;&lt;channels&gt;&lt;CHECKSUM&gt;&lt;ETX&gt;  
// In Hex : 0x02 0x06 0x4f 0x07 0xa2 0x03  
Connect to IP and send command and wait for answer:

 Set Variable \[$sock ; Value:MBS ("[Socket.Connect](SocketConnect.md)";test::IP ; 16128)\]  
If \[MBS ("IsError")\]  
 Show Custom Dialog \["Failed to connect"\]  
Else  
 Set Variable \[$write ; Value:MBS ("Socket.WriteHex"; $sock ; test::query )\]  
 Pause/Resume Script \[Duration (seconds): 1\]  
 Set Field \[test::response ; MBS ("[Socket.ReadHex](SocketReadHex.md)"; $sock ; 20)\]  
 Show Custom Dialog \["Hex: " &amp; test::response &amp; ¶ &amp; "Text: " &amp; MBS ( "[Text.DecodeFromHex](TextDecodeFromHex.md)"; test::response )\]  
 Set Variable \[$sock ; Value:MBS ("[Socket.Close](SocketClose.md)"; $sock )\]  
End If  
### See also

- [IsError](IsError.md)
- [Socket.Close](SocketClose.md)
- [Socket.Connect](SocketConnect.md)
- [Socket.LastError](SocketLastError.md)
- [Socket.Read](SocketRead.md)
- [Socket.ReadHex](SocketReadHex.md)
- [Socket.Write](SocketWrite.md)
- [Socket.WriteByte](SocketWriteByte.md)
- [Socket.WriteMLLP](SocketWriteMLLP.md)
- [Text.DecodeFromHex](TextDecodeFromHex.md)

### Example Databases

- [Network/Zebra ZPL Sample](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Network/Zebra%20ZPL%20Sample.shtml#1ScriptAnchor_)

### Blog Entries

- [Socket changes for MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2020-08-31/Socket_changes_for_MBS_FileMak/monkeybreadsoftware_blog_filemaker)
- [More Text Encoding conversion for FileMaker](https://www.mbsplugins.de/archive/2019-08-14/More_Text_Encoding_conversion_/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 25th February 2026

  
[Socket.WriteByte](SocketWriteByte.md) - [Socket.WriteMLLP](SocketWriteMLLP.md)

[HTML Version](SocketWriteHex.shtml)