({{, (RefLink[SocketObject, paclet:ref/SocketObject])[…] 
represents a network socket connection.}})

OpenersNotesSection(Spacer1)Details

Both (RefLink[SocketConnect, paclet:ref/SocketConnect]) and (RefLink[SocketOpen, paclet:ref/SocketOpen]) give (RefLink[SocketObject, paclet:ref/SocketObject])[…].

Functions that operate on socket connections specified by (RefLink[SocketObject, paclet:ref/SocketObject]) include (RefLink[Read, paclet:ref/Read]), (RefLink[Write, paclet:ref/Write]), (RefLink[ReadString, paclet:ref/ReadString]), (RefLink[WriteString, paclet:ref/WriteString]), (RefLink[BinaryRead, paclet:ref/BinaryRead]) and (RefLink[BinaryWrite, paclet:ref/BinaryWrite]).

Socket connections are closed using (RefLink[Close, paclet:ref/Close]).

(RefLink[SocketConnect, paclet:ref/SocketConnect]) creates a socket connection from a source address to a destination address.

(RefLink[SocketOpen, paclet:ref/SocketOpen]) opens a socket at a destination address that accepts connections from source addresses.

Properties of a socket connection can be found using (RefLink[SocketObject, paclet:ref/SocketObject])[…][prop] or (RefLink[Options, paclet:ref/Options])[SocketObject[…],prop]. When applicable, options can be set using (RefLink[SetOptions, paclet:ref/SetOptions]).

Properties for all connections include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Open a connection to a server specified by a URL:

socket = SocketConnect["http://exampledata.wolfram.com"]

Write to the socket:

WriteString[socket,"GET /50states.txt HTTP/1.0 \n\n"]

Read the result as a string:

Snippet[ReadString[socket]]

Close the socket connection:

Close[socket]

Connect to a server:

socket = SocketConnect["http://wolfram.com"]

Get the outgoing "SourceIPAddress" on your machine for this socket:

socket["SourceIPAddress"]

Close the socket:

Close[socket]

Open a "ZMQ" socket to listen on and connect a client to it:

server= SocketOpen[Automatic,"ZMQ"];
client=SocketConnect[server]

The default "Protocol" for "ZMQ" sockets is "ZMQ_Pair":

client["Protocol"]

Close the socket:

Close/@{server,client}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Sockets, paclet:ref/Sockets])  ▪  (RefLink[SocketConnect, paclet:ref/SocketConnect])  ▪  (RefLink[InputStream, paclet:ref/InputStream])  ▪  (RefLink[OutputStream, paclet:ref/OutputStream])  ▪  (RefLink[CloudObject, paclet:ref/CloudObject])  ▪  (RefLink[DeviceObject, paclet:ref/DeviceObject])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Network Programming, paclet:guide/NetworkProgramming])}, {▪(RefLinkPlain[External Language Interfaces, paclet:guide/ExternalLanguageInterfaces])}, {▪(RefLinkPlain[HTTP Requests & Responses, paclet:guide/HTTPRequestsAndResponses])}})}})