TCP

TCP class reference
TCP API Reference

With TCP, data can be sent and received from a device to a specified IP address or domain using TCP. It can be used to communicate with devices in the same network where the device exists, and can be used to display the router's configuration screen and acquire video footage from network monitoring cameras.

Connection.

One or more TCPs are available and you can get a free one with obniz.getFreeTcp(). If it doesn't exist, it will be thrown.
You can use connectWait() to make a connection by specifying the port number and IP or domain name. Do it. If it fails, an error is thrown.

// JavaScript Example
var tcp = obniz.getFreeTcp();
tcp.connectWait(80,"google.com");

You can also use end() to disconnect.

// JavaScript Example
var tcp = obniz.getFreeTcp();
tcp.connectWait(80,"google.com");
await obniz.wait(1000);
tcp.end();

Reading and writing

Use write for writing and [onreceive](https:// obniz.github.io/obniz/obnizjs/classes/obnizcore.components.tcp.html#onreceive) to specify the function. The function specified in onerror will be called when some error occurs.

// JavaScript Example
var tcp = obniz.getFreeTcp();
tcp.onerror = state => {
  console.log(state);
};
tcp.onreceive = data => {
  console.log(data);
};
tcp.connectWait(80,"google.com");
tcp.write('hello');