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.




// version 1.2.21
 
import java.net.Socket
 
fun main(args: Array<String>) {
    val sock = Socket("localhost", 256)
    sock.use {
        it.outputStream.write("hello socket world".toByteArray())
    }
}