Wolfram Language

Systems-Level Functionality

Connect Directly to Network Sockets

Network sockets are endpoints in connections across a computer network. Direct socket communication is used for lower-level interactions with network and internet connections. While most users' needs will be fulfilled by the higher-level Web Operations, raw socket connections are also an option.

Open a socket.

In[1]:=
Click for copyable input
sock = SocketConnect[{"wolfram.com", 80}]
Out[1]=

Write a request on the socket.

In[2]:=
Click for copyable input
WriteString[sock, "GET /index.php HTTP/1.0 \n\n"]

Read the response.

In[3]:=
Click for copyable input
StringTake[ReadString[sock], 200]
Out[3]=

Close the socket.

In[4]:=
Click for copyable input
Close[sock]
Out[4]=

Related Examples

de es fr ja ko pt-br ru zh