For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket.

Catching any exceptions or errors is not required.




without js -- (sockets)
include builtins\sockets.e
constant msg = "hello socket world"
atom sock = socket(AF_INET, SOCK_STREAM)
if sock>=0 then
    atom pSockAddr = sockaddr_in(AF_INET, "localhost", 256)
    integer res = connect(sock, pSockAddr)
    if res=SOCKET_ERROR then
        crash("connect (%v)",{get_socket_error()})
    end if
    string pm = msg
    while true do
        integer len = length(pm),
                slen = send(sock, pm)
        if slen<0 or slen=len then exit end if
        pm = pm[slen+1..$]
    end while
    closesocket(sock)
end if
WSACleanup()
