This object implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines.

1 Socket Client

SocketClient Object can be created invoking a new Ax.net.SocketClient(hostname, port) constructor.

Copy
<script>
    var socketClient = new Ax.net.SocketClient(192.168.10.11, 4728);
</script>
Return Method Description
SocketClient setTcpNoDelay(boolean mode) Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).
SocketClient setSoTimeout(int timeout) Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
SocketClient write(String message) Send message to server thru socket connection.
SocketClient read() Read data from server thru socket connection.

1.1 Examples

1.1.1 Example 1

The following example, shows a basic connection to a socked endpoint, sends a message and gets a response.

Copy
<script>
    var socket = new Ax.net.SocketClient("pedidos.myediserver.com", 6969)
    	.addConnectEvent((socket) => {
    		console.log("Client socket connected " + socket);
    	})	
    
    	.addDisconnectEvent((socket) => {
    		console.log("Client disconnected:" + socket);
    	})
    ;
    
    socket.connect();
    
    var ex = socket.write(`010120081101161501CODIGO   USUARIOPASSWORD
101077776000        0000046007205 00      00000000000   020020080509  .
102000000071278600001
10500002000002000000
0199
    `);
    
    var s = socket.read();
    console.log(s);
</script>
010120200218033515CODIGO   USUARIOPASSWORD
201077776000        0000046007000000000000                              
0199

2 Socket Server