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.




import java.net.Socket
 
object sendSocketData {
 
  def sendData(host: String, msg: String) {
    val sock = new Socket(host, 256)
    sock.getOutputStream().write(msg.getBytes())
    sock.getOutputStream().flush()
    sock.close()
  }
 
  sendData("localhost", "hello socket world")
}