Class: ClientNetwork

ClientNetwork~ClientNetwork()

Network layer class. It emmits events for each recieved message. Implements functions to send messages over the network

Constructor

new ClientNetwork()

Constructor for the ClientNetwork. Only inicialices the super class.
Source:
Fires:
  • ClientNetwork#event:handshake-Res
  • ClientNetwork#event:TCP-Res
  • ClientNetwork#event:TCP-Req
  • ClientNetwork#event:UDP-Res
  • ClientNetwork#event:UDP-Req

Extends

  • EventEmitter

Members

handshakeSocket :net.Socket

The handshake socket.
Type:
  • net.Socket
Source:

TCPSocket :net.Socket

The TCP Q4S socket.
Type:
  • net.Socket
Source:

UDPSocket :dgram.Socket

The UDP Q4S socket.
Type:
  • dgram.Socket
Source:

Methods

closeHandshake()

Close the handshake socket.
Source:

closeNetwork()

Close all communications. Call to clean up at the end.
Source:

(async) initHandshakeSocket(ip, port, localPort) → {Promise}

Async method to create the handshake socket. After completition the sendHandshakeTCP method can be called to send messages. After completition the class starts to emit events.
Parameters:
Name Type Description
ip string The string containing the ip to connect
port string Port to connect
localPort string Origin port for the handshake connection.
Source:
Returns:
On success nothing, on error the network error.
Type
Promise

(async) initQ4sSocket(ip, port, localPort, portUDP, listeningPortUDP) → {Promise}

Async method to create both q4s sockets for the connection.
Parameters:
Name Type Description
ip string The string containing the ip to connect
port Number TCP port to connect
localPort Number Origin port for the TCP connection
portUDP Number Port for UDP communication
listeningPortUDP Number Port to listen for UDP messages.
Source:
Returns:
On success nothing, on error the network error.
Type
Promise

sendHandshakeTCP(msg)

Send a message trough the handshake socket.
Parameters:
Name Type Description
msg ReSQ4S | Request The request or response to send.
Source:

sendTCP(msg)

Send a message trough the q4s TCP socket.
Parameters:
Name Type Description
msg ReSQ4S | Request The request or response to send.
Source:

sendUDP(msg)

Send a message trough the q4s UDP socket.
Parameters:
Name Type Description
msg Response | Request The request or response to send.
Source: