How to talk to the network in QtScript

Working with Network Ports in QtScript is a lot like Serial Ports, except over a network instead of a serial port:

var _open = mywindow.findChild("_open");
var _close = mywindow.findChild("_close");
var _results = mywindow.findChild("_results");
var _portLit = mywindow.findChild("_portLit");
var _port = mywindow.findChild("_port");

var bytes = new QByteArray("");
var server = new QTcpServer(mywindow);
var client;
_port.setValidator(mainwindow.qtyVal());
function sOpenTcpServer() {

  if (!server.listen(QHostAddress.Any, (_port.text == "" ? 6666 : _port.text))) {
    QMessageBox.critical(mywindow, "Error", "Server could not start");
    return;
  }
  else {
    server.newConnection.connect(newConnection);
    _port.text = server.serverPort();
  }
}

function newConnection() {
  client = server.nextPendingConnection();
  client.readyRead.connect(sHandleReadyRead);
}

function sHandleClose() {
  if (server.isListening()) {
    server.close();
  }
  mywindow.close();
}

function sHandleReadyRead() {
  var buffer = new QByteArray("");
  buffer.append(client.readLine());
  _results.append(buffer);
  client.close();
  buffer.clear();
}

function parseInput(input) {

// do something with input here

}

_close.clicked.connect(sHandleClose);
_open.clicked.connect(sOpenTcpServer);