RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • accept
    • read
    • readline
    • tcpclient
    • tcpserver
    • write

write — Write numeric or text payloads to a TCP client connection.

write(t, data, ...) sends binary or text payloads through a tcpclient connection with selectable datatype conversion, byte order, and timeout handling.

Syntax

count = write(client, data)
count = write(client, data, datatype)

Inputs

client
Type
Any
Required
Yes
Description
tcpclient object with sealed session-owned socket authority.
data
Type
Any
Required
Yes
Description
Payload to send.
datatype
Type
StringScalar
Required
No
Default
class(data)
Description
Data type label (for example "uint8", "double", "char", "string").
NameTypeRequiredDefaultDescription
clientAnyYes—tcpclient object with sealed session-owned socket authority.
dataAnyYes—Payload to send.
datatypeStringScalarNoclass(data)Data type label (for example "uint8", "double", "char", "string").

Returns

count
Type
NumericScalar
Description
Number of elements written to the socket.
NameTypeDescription
countNumericScalarNumber of elements written to the socket.

Errors

RunMat:network:UnsupportedTarget
When
A native TCP socket operation is requested in a browser target.
Message
native TCP sockets are unavailable on this target
RunMat:Cancelled
When
An invocation is cancelled before or during a pending TCP operation.
Message
TCP invocation was cancelled
RunMat:write:InvalidTcpClient
When
Client handle is missing, malformed, invalid, or disconnected.
Message
write: invalid tcpclient handle
IdentifierWhenMessage
RunMat:network:UnsupportedTargetA native TCP socket operation is requested in a browser target.native TCP sockets are unavailable on this target
RunMat:CancelledAn invocation is cancelled before or during a pending TCP operation.TCP invocation was cancelled
RunMat:write:InvalidTcpClientClient handle is missing, malformed, invalid, or disconnected.write: invalid tcpclient handle
RunMat:write:InvalidInputArgument list shape is unsupported for write.write: invalid argument list
RunMat:write:InvalidDataPayload cannot be converted to the requested datatype.write: invalid data payload
RunMat:write:InvalidDataTypeDatatype argument is not a supported scalar text label.write: invalid datatype argument
RunMat:write:NotConnectedClient has no active socket connection.write: tcpclient is disconnected
RunMat:write:TimeoutSocket write exceeds configured timeout.write: timed out while sending data
RunMat:write:ConnectionClosedPeer closes socket before payload is fully written.write: connection closed before all data was sent
RunMat:write:InternalErrorInternal socket/control-flow conversion fails.write: internal socket error

Payload and datatype

write(t, data) sends values using the datatype of data. Double, single, and all eight native integer classes retain their native wire width and signedness.

write(t, data, datatype) converts before encoding. Supported tokens are "uint8", "int8", "uint16", "int16", "uint32", "int32", "uint64", "int64", "single", "double", "char", and "string". Integer conversions saturate to the destination range; "char" uses single-byte character codes and "string" sends UTF-8 text.

The compatibility target documents real row and column vectors. Matrix and multidimensional numeric data, sparse data, and logical data are separate RunMat language extensions available in runmat mode.

The live client’s captured ByteOrder controls multi-byte numeric serialization. "little-endian" is the default, while "big-endian" matches network byte order. Editing a visible copied property does not reconfigure the socket.

RunMat returns the number of elements written when requested. The compatibility target documents write without an output, so assigning this value is RunMat-specific.

Connection, placement, and errors

The socket write executes on the host. Automatically resident data is gathered through its owning provider before byte conversion. Explicit gpuArray input requires runmat mode and is rejected in compatible modes before provider or socket access.

A write continues until all encoded bytes are sent or an error occurs. A timeout raises RunMat:write:Timeout; a peer closure before completion raises RunMat:write:ConnectionClosed and marks the live client disconnected. A write may already have sent a prefix before either error.

Networking terminates fusion; no accelerator kernel executes for this identity. Large payloads use the client’s timeout and byte-order settings.

Illustrative programs

Sending an array of bytes to an echo service

client = tcpclient("127.0.0.1", 50000);

count = write(client, uint8(1:4))

Expected display: count =

4

Writing doubles with explicit byte order

client = tcpclient("localhost", 50001, "ByteOrder", "big-endian");

values = [1.5 2.5 3.5];

write(client, values, "double")

Transmitting ASCII text

client = tcpclient("127.0.0.1", 50002);

write(client, "RunMat TCP", "char")

Sending UTF-8 encoded strings

client = tcpclient("127.0.0.1", 50003);

write(client, "Διακριτό", "string")

Handling connection closures

client = tcpclient("example.com", 12345, "Timeout", 0.25);

try

write(client, uint8([1 2 3 4]));

catch err

disp(err.identifier)

end

Possible display when the peer closes early: RunMat:write:ConnectionClosed

Example

Send exact bytes to a local peer

client = tcpclient('__RUNMAT_LOOPBACK_HOST__', __RUNMAT_LOOPBACK_PORT__);
count = write(client, uint8([1 2 3 4]));
assert(count == 4);
close(client);

Using write with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how write changes the result.

Run a small write example, explain the result, then change one input and compare the output.

FAQ

How many output values does write return?⌄

RunMat returns the number of elements written when requested. The compatibility target documents no output, so portable code should call write without assigning a result.

Does write support complex numbers?⌄

No. The input must be real. Pass separate real and imaginary parts or convert to a byte representation manually.

How are values rounded when converting to integer datatypes?⌄

Floating-point inputs are rounded to the nearest integer and then saturated to the target range (for example uint8(255.7) becomes 255, and int8(-128.2) becomes -128).

What happens to GPU-resident tensors?⌄

Automatically resident tensors are gathered transparently. An explicit gpuArray argument requires runmat mode because the compatibility target does not document interactive device input for this operation.

Can I stream large payloads?⌄

write loops until the entire payload has been sent or an error occurs. Large payloads honour the client’s timeout and byte-order settings; a failed call can already have sent a prefix.

Related Io functions

Net

accept · read · readline · tcpclient · tcpserver

Repl Fs

addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · filesep · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · memmapfile.subsasgn · memmapfile.subsref · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite

Tabular

arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · getvaropts · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · setvaropts · setvartype · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite

Audio

audioinfo · audioread

Io

clc · diary · disp · display · format · input

Data

commit · data.copy · data.create · data.delete · data.exists · data.export · data.import · data.inspect · data.list · data.move · data.open · DataArray.chunk_shape · DataArray.codec · DataArray.dtype · DataArray.fill · DataArray.name · DataArray.rank · DataArray.read · DataArray.resize · DataArray.shape · DataArray.write · Dataset.array · Dataset.arrays · Dataset.attrs · Dataset.begin · Dataset.get_attr · Dataset.has_array · Dataset.id · Dataset.path · Dataset.refresh · Dataset.set_attr · Dataset.set_attrs · Dataset.snapshot · Dataset.version · DataTransaction.abort · DataTransaction.commit · DataTransaction.create_array · DataTransaction.delete_array · DataTransaction.fill · DataTransaction.id · DataTransaction.resize · DataTransaction.set_attr · DataTransaction.set_attrs · DataTransaction.status · DataTransaction.write

Filetext

fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines

Archive

gunzip · gzip · unzip

Hdf5

h5disp · h5info · h5read · h5write · h5writeatt · hdf5info · hdf5read · hdf5write

Import

importdata · textscan

Json

jsondecode · jsonencode

Mat

load · matfile · matlab.io.MatFile.subsasgn · matlab.io.MatFile.subsref · save

Http

sendmail · urldecode · urlencode · weboptions · webread · websave · webwrite

Related guides

  • MATLAB language extensions

Source you can read

Every RunMat function's source is public. Read exactly how write is executed, line by line, in Rust.

  • View the source for write in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Payload and datatype
  • Connection, placement, and errors
  • Illustrative programs
  • Example
  • Send exact bytes to a local peer
  • Using write with coding agents
  • FAQ
  • Related Io functions
  • Net
  • Repl Fs
  • Tabular
  • Audio
  • Io
  • Data
  • Filetext
  • Archive
  • Hdf5
  • Import
  • Json
  • Mat
  • Http
  • Related guides
  • Source you can read
  • About RunMat