-
Notifications
You must be signed in to change notification settings - Fork 46
/
Ex2.hx
90 lines (67 loc) · 1.92 KB
/
Ex2.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Compile with
// haxe -D nodejs -cp . -js ex2.js -main Ex2
import js.Node;
class Ex2 {
public static
function main() {
clientTest();
// tcpTest();
//flashCrossDomain();
}
public static function
tcpTest() {
var tcp = Node.net;
var s = tcp.createServer(function(c) {
c.addListener('connect',function(d) {
trace("got connection");
c.write("hello\r\n");
});
c.addListener('data',function(d) {
c.write(d);
});
c.addListener('data',function(d) {
trace("lost connection");
c.end();
});
});
s.listen(5000,"localhost");
trace("here");
}
public static function
flashCrossDomain() {
var tcp = Node.net;
var s = tcp.createServer(function(c) {
c.addListener('connect',function(d) {
c.write('<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="1138,1139,1140" />
</cross-domain-policy>');
c.end();
});
c.addListener('end',function(d) {
trace("lost connection");
c.end();
});
});
trace("args[1] "+Node.process.argv[2]);
s.listen(843,Node.process.argv[2]);
}
static function
clientTest() {
var
console = Node.console,
http = Node.http,
google = http.createClient(80, "www.google.cl"),
request = google.request("GET","/", {host: "www.google.cl"});
request.addListener('response',function (response) {
console.log("STATUS: " + response.statusCode);
console.log("HEADERS: " + Node.stringify(response.headers));
response.addListener("data", function (chunk) {
console.log("BODY: " + chunk);
});
});
request.end();
}
}