I/O and Network¶
General I/O¶
STDOUT¶Global variable referring to the standard out stream.
STDERR¶Global variable referring to the standard error stream.
STDIN¶Global variable referring to the standard input stream.
open(file_name[, read, write, create, truncate, append]) → IOStream¶Open a file in a mode specified by five boolean arguments. The default is to open files for reading only. Returns a stream for accessing the file.
open(file_name[, mode]) → IOStreamAlternate syntax for open, where a string-based mode specifier is used instead of the five booleans. The values of
modecorrespond to those fromfopen(3)or Perlopen, and are equivalent to setting the following boolean groups:r read r+ read, write w write, create, truncate w+ read, write, create, truncate a write, create, append a+ read, write, create, append
open(command, mode::AbstractString="r", stdio=DevNull)Start running
commandasynchronously, and return a tuple(stream,process). Ifmodeis"r", thenstreamreads from the process’s standard output andstdiooptionally specifies the process’s standard input stream. Ifmodeis"w", thenstreamwrites to the process’s standard input andstdiooptionally specifies the process’s standard output stream.
open(f::Function, command, mode::AbstractString="r", stdio=DevNull)Similar to
open(command,mode,stdio), but callsf(stream)on the resulting read or write stream, then closes the stream and waits for the process to complete. Returns the value returned byf.
open(f::Function, args...)Apply the function
fto the result ofopen(args...)and close the resulting file descriptor upon completion.Example:
open(readall,"file.txt")
IOBuffer() → IOBuffer¶Create an in-memory I/O stream.
IOBuffer(size::Int)Create a fixed size IOBuffer. The buffer will not grow dynamically.
IOBuffer(string)Create a read-only IOBuffer on the data underlying the given string
IOBuffer([data][, readable, writable[, maxsize]])Create an IOBuffer, which may optionally operate on a pre-existing array. If the readable/writable arguments are given, they restrict whether or not the buffer may be read from or written to respectively. By default the buffer is readable but not writable. The last argument optionally specifies a size beyond which the buffer may not be grown.
takebuf_array(b::IOBuffer)¶Obtain the contents of an
IOBufferas an array, without copying. Afterwards, the IOBuffer is reset to its initial state.
takebuf_string(b::IOBuffer)¶Obtain the contents of an
IOBufferas a string, without copying. Afterwards, the IOBuffer is reset to its initial state.
fdio([name::AbstractString, ]fd::Integer[, own::Bool]) → IOStream¶Create an
IOStreamobject from an integer file descriptor. Ifownistrue, closing this object will close the underlying descriptor. By default, anIOStreamis closed when it is garbage collected.nameallows you to associate the descriptor with a named file.
flush(stream)¶Commit all currently buffered writes to the given stream.
close(stream)¶Close an I/O stream. Performs a
flushfirst.
write(stream, x)¶Write the canonical binary representation of a value to the given stream. Returns the number of bytes written into the stream.
You can write multiple values with the same :func:
writecall. i.e. the following are equivalent:write(stream,x,y...)write(stream,x)+write(stream,y...)
read(stream, type)¶Read a value of the given type from a stream, in canonical binary representation.
read(stream, type, dims)Read a series of values of the given type from a stream, in canonical binary representation.
dimsis either a tuple or a series of integer arguments specifying the size ofArrayto return.
read!(stream, array::Array)¶Read binary data from a stream, filling in the argument
array.
readbytes!(stream, b::Vector{UInt8}, nb=length(b); all=true)¶Read at most
nbbytes from the stream intob, returning the number of bytes read (increasing the size ofbas needed).See
readbytesfor a description of thealloption.
readbytes(stream, nb=typemax(Int); all=true)¶Read at most
nbbytes from the stream, returning aVector{UInt8}of the bytes read.If
allistrue(the default), this function will block repeatedly trying to read all requested bytes, until an error or end-of-file occurs. Ifallisfalse, at most onereadcall is performed, and the amount of data returned is device-dependent. Note that not all stream types support thealloption.
position(s)¶Get the current position of a stream.
seek(s, pos)¶Seek a stream to the given position.
seekstart(s)¶Seek a stream to its beginning.
seekend(s)¶Seek a stream to its end.
skip(s, offset)¶Seek a stream relative to the current position.
mark(s)¶Add a mark at the current position of stream
s. Returns the marked position.See also
unmark(),reset(),ismarked()
unmark(s)¶Remove a mark from stream
s. Returnstrueif the stream was marked,falseotherwise.See also
mark(),reset(),ismarked()
reset(s)¶Reset a stream
sto a previously marked position, and remove the mark. Returns the previously marked position. Throws an error if the stream is not marked.See also
mark(),unmark(),ismarked()
eof(stream) → Bool¶Tests whether an I/O stream is at end-of-file. If the stream is not yet exhausted, this function will block to wait for more data if necessary, and then return
false. Therefore it is always safe to read one byte after seeingeofreturnfalse.eofwill returnfalseas long as buffered data is still available, even if the remote end of a connection is closed.
isreadonly(stream) → Bool¶Determine whether a stream is read-only.
isopen(object) → Bool¶Determine whether an object - such as a stream, timer, or mmap – is not yet closed. Once an object is closed, it will never produce a new event. However, a closed stream may still have data to read in its buffer, use
eofto check for the ability to read data. Usepoll_fdto be notified when a stream might be writable or readable.
serialize(stream, value)¶Write an arbitrary value to a stream in an opaque format, such that it can be read back by
deserialize. The read-back value will be as identical as possible to the original. In general, this process will not work if the reading and writing are done by different versions of Julia, or an instance of Julia with a different system image.Ptrvalues are serialized as all-zero bit patterns (NULL).
deserialize(stream)¶Read a value written by
serialize.
print_escaped(io, str::AbstractString, esc::AbstractString)¶General escaping of traditional C and Unicode escape sequences, plus any characters in esc are also escaped (with a backslash).
print_unescaped(io, s::AbstractString)¶General unescaping of traditional C and Unicode escape sequences. Reverse of
print_escaped().
print_joined(io, items, delim[, last])¶Print elements of
itemstoiowithdelimbetween them. Iflastis specified, it is used as the final delimiter instead ofdelim.
print_shortest(io, x)¶Print the shortest possible representation, with the minimum number of consecutive non-zero digits, of number
x, ensuring that it would parse to the exact same number.
fd(stream)¶Returns the file descriptor backing the stream or file. Note that this function only applies to synchronous
File‘s andIOStream‘s not to any of the asynchronous streams.
redirect_stdout()¶Create a pipe to which all C and Julia level
STDOUToutput will be redirected. Returns a tuple(rd,wr)representing the pipe ends. Data written toSTDOUTmay now be read from the rd end of the pipe. The wr end is given for convenience in case the oldSTDOUTobject was cached by the user and needs to be replaced elsewhere.
redirect_stdout(stream)Replace
STDOUTby stream for all C and Julia level output toSTDOUT. Note thatstreammust be a TTY, aPipeor aTCPSocket.
redirect_stderr([stream])¶Like redirect_stdout, but for STDERR
redirect_stdin([stream])¶Like redirect_stdout, but for STDIN. Note that the order of the return tuple is still (rd,wr), i.e. data to be read from STDIN, may be written to wr.
readchomp(x)¶Read the entirety of
xas a string but remove trailing newlines. Equivalent tochomp(readall(x)).
truncate(file, n)¶Resize the file or buffer given by the first argument to exactly
nbytes, filling previously unallocated space with ‘\0’ if the file or buffer is grown
skipchars(stream, predicate; linecomment::Char)¶Advance the stream until before the first character for which
predicatereturnsfalse. For exampleskipchars(stream,isspace)will skip all whitespace. If keyword argumentlinecommentis specified, characters from that character through the end of a line will also be skipped.
countlines(io[, eol::Char])¶Read
iountil the end of the stream/file and count the number of lines. To specify a file pass the filename as the first argument. EOL markers other than ‘\n’ are supported by passing them as the second argument.
PipeBuffer()¶An IOBuffer that allows reading and performs writes by appending. Seeking and truncating are not supported. See IOBuffer for the available constructors.
PipeBuffer(data::Vector{UInt8}[, maxsize])Create a PipeBuffer to operate on a data vector, optionally specifying a size beyond which the underlying Array may not be grown.
readavailable(stream)¶Read all available data on the stream, blocking the task only if no data is available. The result is a
Vector{UInt8,1}.
Text I/O¶
show(x)¶Write an informative text representation of a value to the current output stream. New types should overload
show(io,x)where the first argument is a stream. The representation used byshowgenerally includes Julia-specific formatting and type information.
showcompact(x)¶Show a more compact representation of a value. This is used for printing array elements. If a new type has a different compact representation, it should overload
showcompact(io,x)where the first argument is a stream.
showall(x)¶Similar to
show, except shows all elements of arrays.
summary(x)¶Return a string giving a brief description of a value. By default returns
string(typeof(x)). For arrays, returns strings like “2x2 Float64 Array”.
print(x)¶Write (to the default output stream) a canonical (un-decorated) text representation of a value if there is one, otherwise call
show. The representation used byprintincludes minimal formatting and tries to avoid Julia-specific details.
print_with_color(color::Symbol, [io, ]strings...)¶Print strings in a color specified as a symbol, for example
:redor:blue.
info(msg)¶Display an informational message. Argument
msgis a string describing the information to be displayed.
warn(msg)¶Display a warning. Argument
msgis a string describing the warning to be displayed.
@printf([io::IOStream, ]"%Fmt", args...)¶Print
argsusing Cprintf()style format specification string. Optionally, anIOStreammay be passed as the first argument to redirect output.
@sprintf("%Fmt", args...)¶Return
@printfformatted output as string.julia>s=@sprintf"this is a %s%15.1f""test"34.567;julia>println(s)thisisatest34.6
sprint(f::Function, args...)¶Call the given function with an I/O stream and the supplied extra arguments. Everything written to this I/O stream is returned as a string.
showerror(io, e)¶Show a descriptive representation of an exception object.
dump(x)¶Show all user-visible structure of a value.
xdump(x)¶Show all structure of a value, including all fields of objects.
readall(stream::IO)¶Read the entire contents of an I/O stream as a string.
readall(filename::AbstractString)Open
filename, read the entire contents as a string, then close the file. Equivalent toopen(readall,filename).
readline(stream=STDIN)¶Read a single line of text, including a trailing newline character (if one is reached before the end of the input), from the given
stream(defaults toSTDIN),
readuntil(stream, delim)¶Read a string, up to and including the given delimiter byte.
readlines(stream)¶Read all lines as an array.
eachline(stream)¶Create an iterable object that will yield each line from a stream.
readdlm(source, delim::Char, T::Type, eol::Char; header=false, skipstart=0, skipblanks=true, use_mmap, ignore_invalid_chars=false, quotes=true, dims, comments=true, comment_char='#')¶Read a matrix from the source where each line (separated by
eol) gives one row, with elements separated by the given delimeter. The source can be a text file, stream or byte array. Memory mapped files can be used by passing the byte array representation of the mapped segment as source.If
Tis a numeric type, the result is an array of that type, with any non-numeric elements asNaNfor floating-point types, or zero. Other useful values ofTincludeASCIIString,AbstractString, andAny.If
headeristrue, the first row of data will be read as header and the tuple(data_cells,header_cells)is returned instead of onlydata_cells.Specifying
skipstartwill ignore the corresponding number of initial lines from the input.If
skipblanksistrue, blank lines in the input will be ignored.If
use_mmapistrue, the file specified bysourceis memory mapped for potential speedups. Default istrueexcept on Windows. On Windows, you may want to specifytrueif the file is large, and is only read once and not written to.If
ignore_invalid_charsistrue, bytes insourcewith invalid character encoding will be ignored. Otherwise an error is thrown indicating the offending character position.If
quotesistrue, column enclosed within double-quote (”) characters are allowed to contain new lines and column delimiters. Double-quote characters within a quoted field must be escaped with another double-quote. Specifyingdimsas a tuple of the expected rows and columns (including header, if any) may speed up reading of large files. Ifcommentsistrue, lines beginning withcomment_charand text followingcomment_charin any line are ignored.
readdlm(source, delim::Char, eol::Char; options...)If all data is numeric, the result will be a numeric array. If some elements cannot be parsed as numbers, a cell array of numbers and strings is returned.
readdlm(source, delim::Char, T::Type; options...)The end of line delimiter is taken as
n.
readdlm(source, delim::Char; options...)The end of line delimiter is taken as
n. If all data is numeric, the result will be a numeric array. If some elements cannot be parsed as numbers, a cell array of numbers and strings is returned.
readdlm(source, T::Type; options...)The columns are assumed to be separated by one or more whitespaces. The end of line delimiter is taken as
n.
readdlm(source; options...)The columns are assumed to be separated by one or more whitespaces. The end of line delimiter is taken as
n. If all data is numeric, the result will be a numeric array. If some elements cannot be parsed as numbers, a cell array of numbers and strings is returned.
writedlm(f, A, delim='\t')¶Write
A(a vector, matrix or an iterable collection of iterable rows) as text tof(either a filename string or anIOstream) using the given delimeterdelim(which defaults to tab, but can be any printable Julia object, typically aCharorAbstractString).For example, two vectors
xandyof the same length can be written as two columns of tab-delimited text tofby eitherwritedlm(f,[xy])or bywritedlm(f,zip(x,y)).
readcsv(source, [T::Type]; options...)¶Equivalent to
readdlmwithdelimset to comma.
writecsv(filename, A)¶Equivalent to
writedlmwithdelimset to comma.
Base64EncodePipe(ostream)¶Returns a new write-only I/O stream, which converts any bytes written to it into base64-encoded ASCII bytes written to
ostream. Callingcloseon theBase64Pipestream is necessary to complete the encoding (but does not closeostream).
Base64DecodePipe(istream)¶Returns a new read-only I/O stream, which decodes base64-encoded data read from
istream.
base64encode(writefunc, args...)¶base64encode(args...)Given a
write-like functionwritefunc, which takes an I/O stream as its first argument,base64(writefunc,args...)callswritefuncto writeargs...to a base64-encoded string, and returns the string.base64(args...)is equivalent tobase64(write,args...): it converts its arguments into bytes using the standardwritefunctions and returns the base64-encoded string.
base64decode(string)¶Decodes the base64-encoded
stringand returns aVector{UInt8}of the decoded bytes.
Multimedia I/O¶
Just as text output is performed by print and user-defined types
can indicate their textual representation by overloading show,
Julia provides a standardized mechanism for rich multimedia output
(such as images, formatted text, or even audio and video), consisting
of three parts:
- A function
display(x)to request the richest available multimedia display of a Julia objectx(with a plain-text fallback). - Overloading
writemimeallows one to indicate arbitrary multimedia representations (keyed by standard MIME types) of user-defined types. - Multimedia-capable display backends may be registered by subclassing
a generic
Displaytype and pushing them onto a stack of display backends viapushdisplay.
The base Julia runtime provides only plain-text display, but richer displays may be enabled by loading external modules or by using graphical Julia environments (such as the IPython-based IJulia notebook).
display(x)¶display(d::Display, x)display(mime, x)display(d::Display, mime, x)Display
xusing the topmost applicable display in the display stack, typically using the richest supported multimedia output forx, with plain-textSTDOUToutput as a fallback. Thedisplay(d,x)variant attempts to displayxon the given displaydonly, throwing aMethodErrorifdcannot display objects of this type.There are also two variants with a
mimeargument (a MIME type string, such as"image/png"), which attempt to displayxusing the requested MIME type only, throwing aMethodErrorif this type is not supported by either the display(s) or byx. With these variants, one can also supply the “raw” data in the requested MIME type by passingx::AbstractString(for MIME types with text-based storage, such as text/html or application/postscript) orx::Vector{UInt8}(for binary MIME types).
redisplay(x)¶redisplay(d::Display, x)redisplay(mime, x)redisplay(d::Display, mime, x)By default, the
redisplayfunctions simply calldisplay. However, some display backends may overrideredisplayto modify an existing display ofx(if any). Usingredisplayis also a hint to the backend thatxmay be redisplayed several times, and the backend may choose to defer the display until (for example) the next interactive prompt.
displayable(mime) → Bool¶displayable(d::Display, mime) → BoolReturns a boolean value indicating whether the given
mimetype (string) is displayable by any of the displays in the current display stack, or specifically by the displaydin the second variant.
writemime(stream, mime, x)¶The
displayfunctions ultimately callwritemimein order to write an objectxas a givenmimetype to a given I/Ostream(usually a memory buffer), if possible. In order to provide a rich multimedia representation of a user-defined typeT, it is only necessary to define a newwritemimemethod forT, via:writemime(stream,::MIME"mime",x::T)=..., wheremimeis a MIME-type string and the function body callswrite(or similar) to write that representation ofxtostream. (Note that theMIME""notation only supports literal strings; to constructMIMEtypes in a more flexible manner useMIME{symbol("")}.)For example, if you define a
MyImagetype and know how to write it to a PNG file, you could define a functionwritemime(stream,::MIME"image/png",x::MyImage)=...to allow your images to be displayed on any PNG-capableDisplay(such as IJulia). As usual, be sure toimportBase.writemimein order to add new methods to the built-in Julia functionwritemime.Technically, the
MIME"mime"macro defines a singleton type for the givenmimestring, which allows us to exploit Julia’s dispatch mechanisms in determining how to display objects of any given type.
mimewritable(mime, x)¶Returns a boolean value indicating whether or not the object
xcan be written as the givenmimetype. (By default, this is determined automatically by the existence of the correspondingwritemimefunction fortypeof(x).)
reprmime(mime, x)¶Returns an
AbstractStringorVector{UInt8}containing the representation ofxin the requestedmimetype, as written bywritemime(throwing aMethodErrorif no appropriatewritemimeis available). AnAbstractStringis returned for MIME types with textual representations (such as"text/html"or"application/postscript"), whereas binary data is returned asVector{UInt8}. (The functionistext(mime)returns whether or not Julia treats a givenmimetype as text.)As a special case, if
xis anAbstractString(for textual MIME types) or aVector{UInt8}(for binary MIME types), thereprmimefunction assumes thatxis already in the requestedmimeformat and simply returnsx.
stringmime(mime, x)¶Returns an
AbstractStringcontaining the representation ofxin the requestedmimetype. This is similar toreprmimeexcept that binary data is base64-encoded as an ASCII string.
As mentioned above, one can also define new display backends. For
example, a module that can display PNG images in a window can register
this capability with Julia, so that calling display(x) on types
with PNG representations will automatically display the image using
the module’s window.
In order to define a new display backend, one should first create a
subtype D of the abstract class Display. Then, for each MIME
type (mime string) that can be displayed on D, one should
define a function display(d::D,::MIME"mime",x)=... that
displays x as that MIME type, usually by calling reprmime(mime,x). A MethodError should be thrown if x cannot be displayed
as that MIME type; this is automatic if one calls reprmime.
Finally, one should define a function display(d::D,x) that
queries mimewritable(mime,x) for the mime types supported by
D and displays the “best” one; a MethodError should be thrown
if no supported MIME types are found for x. Similarly, some
subtypes may wish to override redisplay(d::D,...). (Again, one
should importBase.display to add new methods to display.)
The return values of these functions are up to the implementation
(since in some cases it may be useful to return a display “handle” of
some type). The display functions for D can then be called
directly, but they can also be invoked automatically from
display(x) simply by pushing a new display onto the display-backend
stack with:
pushdisplay(d::Display)¶Pushes a new display
don top of the global display-backend stack. Callingdisplay(x)ordisplay(mime,x)will displayxon the topmost compatible backend in the stack (i.e., the topmost backend that does not throw aMethodError).
popdisplay()¶popdisplay(d::Display)Pop the topmost backend off of the display-backend stack, or the topmost copy of
din the second variant.
TextDisplay(stream)¶Returns a
TextDisplay<:Display, which can display any object as the text/plain MIME type (only), writing the text representation to the given I/O stream. (The text representation is the same as the way an object is printed in the Julia REPL.)
istext(m::MIME)¶Determine whether a MIME type is text data.
Memory-mapped I/O¶
Mmap.Anonymous(name, readonly, create)¶Create an
IO-like object for creating zeroed-out mmapped-memory that is not tied to a file for use inMmap.mmap. Used bySharedArrayfor creating shared memory arrays.
Mmap.mmap(io::Union{IOStream,AbstractString,Mmap.AnonymousMmap}[, type::Type{Array{T,N}}, dims, offset]; grow::Bool=true, shared::Bool=true)¶Mmap.mmap(type::Type{Array{T, N}}, dims)Create an
Arraywhose values are linked to a file, using memory-mapping. This provides a convenient way of working with data too large to fit in the computer’s memory.The type is an
Array{T,N}with a bits-type element ofTand dimensionNthat determines how the bytes of the array are interpreted. Note that the file must be stored in binary format, and no format conversions are possible (this is a limitation of operating systems, not Julia).dimsis a tuple or singleIntegerspecifying the size or length of the array.The file is passed via the stream argument, either as an open
IOStreamor filename string. When you initialize the stream, use"r"for a “read-only” array, and"w+"to create a new array used to write values to disk.If no
typeargument is specified, the default isVector{UInt8}.Optionally, you can specify an offset (in bytes) if, for example, you want to skip over a header in the file. The default value for the offset is the current stream position for an
IOStream.The
growkeyword argument specifies whether the disk file should be grown to accommodate the requested size of array (if the total file size is < requested array size). Write privileges are required to grow the file.The
sharedkeyword argument specifies whether the resultingArrayand changes made to it will be visible to other processes mapping the same file.For example, the following code:
# Create a file for mmapping# (you could alternatively use mmap to do this step, too)A=rand(1:20,5,30)s=open("/tmp/mmap.bin","w+")# We'll write the dimensions of the array as the first two Ints in the filewrite(s,size(A,1))write(s,size(A,2))# Now write the datawrite(s,A)close(s)# Test by reading it back ins=open("/tmp/mmap.bin")# default is read-onlym=read(s,Int)n=read(s,Int)A2=Mmap.mmap(s,Matrix{Int},(m,n))
creates a
m-by-nMatrix{Int}, linked to the file associated with streams.A more portable file would need to encode the word size—32 bit or 64 bit—and endianness information in the header. In practice, consider encoding binary data using standard formats like HDF5 (which can be used with memory-mapping).
Mmap.mmap(io, BitArray[, dims, offset])Create a
BitArraywhose values are linked to a file, using memory-mapping; it has the same purpose, works in the same way, and has the same arguments, asmmap(), but the byte representation is different.Example:
B=Mmap.mmap(s,BitArray,(25,30000))This would create a 25-by-30000
BitArray, linked to the file associated with streams.
Mmap.sync!(array)¶Forces synchronization between the in-memory version of a memory-mapped
ArrayorBitArrayand the on-disk version.
Network I/O¶
connect([host, ]port) → TCPSocket¶Connect to the host
hoston portport
connect(path) → PipeEndpointConnect to the Named Pipe / Domain Socket at
path
listen([addr, ]port) → TCPServer¶Listen on port on the address specified by
addr. By default this listens on localhost only. To listen on all interfaces passIPv4(0)orIPv6(0)as appropriate.
listen(path) → PipeServerCreate and listen on a Named Pipe / Domain Socket
getaddrinfo(host)¶Gets the IP address of the
host(may have to do a DNS lookup)
parseip(addr)¶Parse a string specifying an IPv4 or IPv6 ip address.
IPv4(host::Integer) → IPv4¶Returns IPv4 object from ip address formatted as Integer
IPv6(host::Integer) → IPv6¶Returns IPv6 object from ip address formatted as Integer
nb_available(stream)¶Returns the number of bytes available for reading before a read from this stream or buffer will block.
accept(server[, client])¶Accepts a connection on the given server and returns a connection to the client. An uninitialized client stream may be provided, in which case it will be used instead of creating a new stream.
listenany(port_hint) -> (UInt16, TCPServer)¶Create a
TCPServeron any port, using hint as a starting point. Returns a tuple of the actual port that the server was created on and the server itself.
poll_fd(fd, timeout_s::Real; readable=false, writable=false)¶Monitor a file descriptor
fdfor changes in the read or write availability, and with a timeout given bytimeout_sseconds.The keyword arguments determine which of read and/or write status should be monitored; at least one of them must be set to
true.The returned value is an object with boolean fields
readable,writable, andtimedout, giving the result of the polling.
poll_file(path, interval_s::Real, timeout_s::Real) -> (previous::StatStruct, current::StatStruct)¶Monitor a file for changes by polling every
interval_sseconds until a change occurs ortimeout_sseconds have elapsed. Theinterval_sshould be a long period; the default is 5.007 seconds.Returns a pair of
StatStructobjects(previous,current)when a change is detected.To determine when a file was modified, compare
mtime(prev)!=mtime(current)to detect notification of changes. However, usingwatch_filefor this operation is preferred, since it is more reliable and efficient, although in some situations it may not be available.
watch_file(path, timeout_s::Real)¶Watch file or directory
pathfor changes until a change occurs ortimeout_sseconds have elapsed.The returned value is an object with boolean fields
changed,renamed, andtimedout, giving the result of watching the file.This behavior of this function varies slightly across platforms. See <https://nodejs.org/api/fs.html#fs_caveats> for more detailed information.
bind(socket::Union{UDPSocket, TCPSocket}, host::IPv4, port::Integer)¶Bind
socketto the givenhost:port. Note that0.0.0.0will listen on all devices.
send(socket::UDPSocket, host::IPv4, port::Integer, msg)¶Send
msgoversockettohost:port.
recv(socket::UDPSocket)¶Read a UDP packet from the specified socket, and return the bytes received. This call blocks.
recvfrom(socket::UDPSocket) -> (address, data)¶Read a UDP packet from the specified socket, returning a tuple of (address, data), where address will be either IPv4 or IPv6 as appropriate.
setopt(sock::UDPSocket; multicast_loop = nothing, multicast_ttl=nothing, enable_broadcast=nothing, ttl=nothing)¶Set UDP socket options.
multicast_loop: loopback for multicast packets (default:true).multicast_ttl: TTL for multicast packets.enable_broadcast: flag must be set totrueif socket will be used for broadcast messages, or else the UDP system will return an access error (default:false).ttl: Time-to-live of packets sent on the socket.
ntoh(x)¶Converts the endianness of a value from Network byte order (big-endian) to that used by the Host.
hton(x)¶Converts the endianness of a value from that used by the Host to Network byte order (big-endian).
ltoh(x)¶Converts the endianness of a value from Little-endian to that used by the Host.
htol(x)¶Converts the endianness of a value from that used by the Host to Little-endian.
ENDIAN_BOM¶The 32-bit byte-order-mark indicates the native byte order of the host machine. Little-endian machines will contain the value 0x04030201. Big-endian machines will contain the value 0x01020304.