Sockets: Difference between revisions

Content added Content deleted
m (Unicon/Icon consistency 2)
m (Unicon/Icon consistency 2)
Line 276: Line 276:
main = withSocketsDo $ sendTo "localhost" (PortNumber $ toEnum 256) "hello socket world"</lang>
main = withSocketsDo $ sendTo "localhost" (PortNumber $ toEnum 256) "hello socket world"</lang>


=={{header|Icon}}==
== Icon and Unicon ==
==={{header|Icon}}===
<lang icon>link cfunc
<lang icon>link cfunc
procedure main ()
procedure main ()
hello("localhost", 1024)
hello("localhost", 1024)
end
end

procedure hello (host, port)
procedure hello (host, port)
write(tconnect(host, port) | stop("unable to connect to", host, ":", port) , "hello socket world")
write(tconnect(host, port) | stop("unable to connect to", host, ":", port) , "hello socket world")
end</lang>
end</lang>
Note: Socket support in native Icon is limited and requires the external helper function cfunc.
Note: Socket support in native Icon is limited and requires the external helper function cfunc.
==={{header|Unicon}}===
Unicon integrated TCP/IP networking and messaging.
<lang unicon>procedure main(arglist) #: usage socket port hostname or socket port
hello(arglist[2]|"",arglist[1])
end

procedure hello(host,port)
local s
/host := ""
host ||:= ":"
host ||:= 0 < 65536 > port | runerr(103,port)
if s := open(host,"n") then {
write(s, "hello socket world.")
close(s)
}
else stop("Unable to connect to ",host,":",port)
return
end</lang>


=={{header|IDL}}==
=={{header|IDL}}==