Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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