Sockets: Difference between revisions
Content added Content deleted
(→{{header|Python}}: Needs to be imported or referenced in its namespace) |
m (Fixed lang tags.) |
||
Line 4: | Line 4: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
{{libheader|GNAT RTL}} |
{{libheader|GNAT RTL}} |
||
<lang ada> |
<lang ada>with GNAT.Sockets; use GNAT.Sockets; |
||
with GNAT.Sockets; use GNAT.Sockets; |
|||
procedure SocketSend is |
procedure SocketSend is |
||
Line 24: | Line 23: | ||
Initialize; |
Initialize; |
||
sendData ("127.0.0.1","Hello Socket World"); |
sendData ("127.0.0.1","Hello Socket World"); |
||
end; |
end;</lang> |
||
⚫ | |||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
modified from |
modified from |
||
Line 153: | Line 151: | ||
ExitSub: |
ExitSub: |
||
DllCall("Ws2_32\WSACleanup") |
DllCall("Ws2_32\WSACleanup") |
||
ExitApp |
ExitApp</lang> |
||
</lang> |
|||
=={{header|C}}== |
=={{header|C}}== |
||
Line 229: | Line 226: | ||
; No value</lang> |
; No value</lang> |
||
<lang>aurora ~% sudo nc -l -p 256 |
<lang lisp>aurora ~% sudo nc -l -p 256 |
||
hello socket world</lang> |
hello socket world</lang> |
||
Line 249: | Line 246: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|GNU Forth|0.7.0}} |
{{works with|GNU Forth|0.7.0}} |
||
<lang forth> |
<lang forth>include unix/socket.fs |
||
include unix/socket.fs |
|||
s" localhost" 256 open-socket |
s" localhost" 256 open-socket |
||
Line 256: | Line 252: | ||
dup s" hello socket world" rot write-socket |
dup s" hello socket world" rot write-socket |
||
close-socket |
close-socket</lang> |
||
</lang> |
|||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell>import Network |
|||
main = withSocketsDo $ sendTo "localhost" (PortNumber $ toEnum 256) "hello socket world"</lang> |
|||
=={{header|Icon}}== |
=={{header|Icon}}== |
||
<lang icon>link cfunc |
|||
procedure main () |
|||
hello("localhost", 1024) |
|||
end |
|||
procedure hello (host, port) |
|||
write(tconnect(host, port) | stop("unable to connect to", host, ":", port) , "Hello socket world") |
|||
end</lang> |
|||
=={{header|IDL}}== |
=={{header|IDL}}== |
||
<tt> |
<tt> |
||
<lang idl>socket, unit, 'localhost',256,/get_lun |
|||
printf,unit,"Hello socket world" |
|||
close, unit</lang> |
|||
</tt> |
</tt> |
||
Line 350: | Line 345: | ||
=={{header|Rhope}}== |
=={{header|Rhope}}== |
||
{{works with|Rhope|alpha 1}} |
{{works with|Rhope|alpha 1}} |
||
<lang rhope>Socket Send(0,0) |
|||
|: |
|||
[New@Net Client["localhost",256]]Put String["hello socket world"] |
|||
⚫ | |||
:| |
|||
The connection is automatically closed when the object is freed. |
The connection is automatically closed when the object is freed. |
||
Line 363: | Line 358: | ||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
<lang seed7>$ include "seed7_05.s7i"; |
|||
include "socket.s7i"; |
|||
const proc: main is func |
|||
local |
|||
var file: sock is STD_NULL; |
|||
begin |
|||
sock := openInetSocket(256); |
|||
writeln(sock, "hello socket world"); |
|||
close(sock); |
|||
end func;</lang> |
|||
Line 380: | Line 375: | ||
This uses fairly verbose and low level messages. This will probably be simplified in the future. |
This uses fairly verbose and low level messages. This will probably be simplified in the future. |
||
<lang slate> |
<lang slate>[ | socket | |
||
[ | socket | |
|||
[ | addr stream | |
[ | addr stream | |
||
addr: (Net SocketAddress newOn: '127.0.0.1:256'). |
addr: (Net SocketAddress newOn: '127.0.0.1:256'). |
||
Line 390: | Line 383: | ||
stream nextPutAll: ('hello socket world' as: ByteArray) |
stream nextPutAll: ('hello socket world' as: ByteArray) |
||
] ensure: [socket close] |
] ensure: [socket close] |
||
] do. |
] do.</lang> |
||
</lang> |
|||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
Line 453: | Line 445: | ||
=={{header|Toka}}== |
=={{header|Toka}}== |
||
<lang toka>needs sockets |
|||
#! A simple abstraction layer that makes writing trivial servers easy |
|||
value| server.socket server.connection server.action | |
|||
[ ( n- ) pBind to server.socket ] is server.setSocket |
|||
[ ( - ) server.socket pAccept to server.connection ] is server.acceptConnection |
|||
[ ( - ) server.connection pClose drop ] is server.closeConnection |
|||
[ ( $- ) >r server.connection r> string.getLength pWrite drop ] is server.send |
|||
[ ( an- ) server.connection -rot pRead drop ] is server.recieve |
|||
[ ( qn- ) swap to server.action server.setSocket |
|||
[ server.acceptConnection server.action invoke server.closeConnection TRUE ] whileTrue ] is server.start |
|||
#! The actual server |
|||
[ " hello socket world" server.send ] 256 server.start</lang> |
|||
=={{header|UnixPipes}}== |
=={{header|UnixPipes}}== |
||
<lang bash>(echo "Hello World" | nc localhost 256 | exit 0)</lang> |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
Line 475: | Line 467: | ||
Using the program <tt>netcat</tt> (<tt>nc</tt>) |
Using the program <tt>netcat</tt> (<tt>nc</tt>) |
||
⚫ | |||
<pre> |
|||
⚫ | |||
</pre> |
|||
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have network access. --> |
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have network access. --> |