# enet_host

### service(callback, timeout) <sub>function</sub>


Poll for and process any available network events (connect, receive, disconnect, or none)
from this host, calling the provided callback for each event. This function loops until
no more events are available in the current timeframe.

Event object properties:
- type: String, one of "connect", "receive", "disconnect", or "none".
- peer: (present if type = "connect") The ENetPeer object for the new connection.
- channelID: (present if type = "receive") The channel on which the data was received.
- data: (present if type = "receive") The received data as a *plain JavaScript object*.
If the JSON parse fails or the data isn't an object, a JavaScript error is thrown.

object as its single argument.


**callback**: A function called once for each available event, receiving an event

**timeout**: (optional) Timeout in milliseconds. Defaults to 0 (non-blocking).


**Returns**: None


### connect(host, port) <sub>function</sub>


Initiate a connection from this host to a remote server. Throws an error if the
connection cannot be started.



**host**: The hostname or IP address of the remote server (e.g. "example.com" or "127.0.0.1").

**port**: The port number to connect to.


**Returns**: An ENetPeer object representing the connection.


### flush() <sub>function</sub>


Flush all pending outgoing packets for this host immediately.



**Returns**: None


### broadcast(data) <sub>function</sub>


Broadcast a JavaScript object to all connected peers on channel 0. The object is
serialized to JSON, and the packet is sent reliably. Throws an error if serialization fails.



**data**: A JavaScript object to broadcast to all peers.


**Returns**: None

