Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
9.3
9.4
9.5
10.0
10.1
10.2
10.3
10.4
10.5
10.6
Statistic
FMM
Blog
Socket.Write
Writes text to the socket.
| Component | Version | macOS | Windows | Linux | Server | FileMaker iOS SDK |
| Socket | 3.1 | Yes | Yes | Yes | Yes | Yes |
Parameters
| Parameter | Description | Example | Flags |
|---|---|---|---|
| SocketID | The socket ID received by Socket.Connect function. | $sock | |
| 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
Writes text to the socket.Returns number of bytes sent. It may take a few milliseconds till data arrives on the other socket.
Result is -1 if socket can't write. See Socket.LastError for error code.
Changed in v10.4 to return error if socket is closed or disconnected instead of -1.
Examples
Write something:
MBS( "Socket.Write"; $sock; "Hello World" )
Write something with DOS text encoding:
MBS( "Socket.Write"; $sock; "Umlauts: äöü"; "DOS" )
Connect to a HTTP Server and wait for answer:
Set Variable [$r; Value:MBS("Trace")]
Set Variable [$sock; Value:MBS("Socket.Connect"; TCP Socket::DomainOrIP; 80)]
If [MBS("IsError")]
Show Custom Dialog ["Error"; $sock]
Exit Script []
End If
Set Variable [$request; Value:"GET "&TCP Socket::Path&" HTTP/1.0¶Host: "&TCP Socket::DomainOrIP&"¶¶"]
Set Variable [$request; Value:MBS("String.ReplaceNewline"; $request; 2)]
Set Field [TCP Socket::RequestUsed; $request]
Set Variable [$r; Value:MBS("Socket.Write"; $sock; $request)]
Pause/Resume Script [Duration (seconds): 1]
Set Variable [$data; Value:MBS("Socket.Read"; $sock; 1000)]
Set Variable [$data; Value:MBS("String.ReplaceNewline"; $data; 1)]
Set Field [TCP Socket::Result; $data]
Set Variable [$r; Value:MBS("Socket.Close"; $sock)]
Send set zero command to scale for MT-SICS (METTLER TOLEDO Standard Interface Command Set):
MBS( "Socket.Write"; $sock; "Z" & Char(13) & Char(10) )
Send print weight command to scale for MT-SICS (METTLER TOLEDO Standard Interface Command Set):
MBS( "Socket.Write"; $sock; "P" & Char(13) & Char(10) )
See also
- IsError
- Socket.Close
- Socket.Connect
- Socket.LastError
- Socket.Read
- Socket.WriteHex
- Socket.WriteMLLP
- Trace
Example Databases
- Network/HTTP Server hosted
- Network/HTTP Server local
- Network/Socket Test/Socket Test
- Network/SSL/TCP Sender SSL
- Network/SSL/TCP Socket SSL
- Network/TCP Send and Receive/TCP Receiver
- Network/TCP Send and Receive/TCP Sender
- Network/TCP Socket
Blog Entries
Release notes
- Version 10.4
- Fixed Socket.Write functions to properly return error instead of -1 in case of errors.
- Improved Socket functions to better return errors. Socket.AvailableBytes, Socket.Write or Socket.Read functions now return an error when socket is disconnected or otherwise broken.
Created 18th August 2014, last changed 31st August 2020
Socket.SetTimeToLive - Socket.WriteByte
Feedback: Report problem or ask question.
Links
MBS Xojo Plugins