File: client-socket-test.js

package info (click to toggle)
duktape 2.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 21,160 kB
  • sloc: ansic: 215,359; python: 5,961; javascript: 4,555; makefile: 477; cpp: 205
file content (16 lines) | stat: -rw-r--r-- 600 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var HOST = 'localhost';
var PORT = 80;

EventLoop.connect(HOST, PORT, function (fd) {
    print('connected to ' + HOST + ':' + PORT + ', fd', fd);
    EventLoop.setReader(fd, function (fd, data) {
        print('read from fd', fd);
        print(new TextDecoder().decode(data));
        // Read until completion, socket is closed by server.
    });
    EventLoop.write(fd, "GET / HTTP/1.1\r\n" +
                        "Host: " + HOST + "\r\n" +
                        "User-Agent: client-socket-test.js\r\n" +
                        "Connection: close\r\n" +
                        "\r\n");
});