Skip to content

Commit 7e3a579

Browse files
committed
Added client to send requests
1 parent e9657ad commit 7e3a579

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

client.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var http = require("http");
2+
3+
var options = {
4+
'host':'127.0.0.1',
5+
'port':'1234',
6+
'path':'/new.txt'
7+
}
8+
9+
var callback = function(response){
10+
11+
var data = "";
12+
13+
response.on('data',function(val){
14+
data+=val;
15+
});
16+
response.on('end',function(){
17+
console.log(data);
18+
});
19+
};
20+
21+
var req = http.request(options,callback);
22+
req.end();
23+
24+
// var http = require('http');
25+
26+
// // Options to be used by request
27+
// var options = {
28+
// host: 'localhost',
29+
// port: '1234',
30+
// path: '/new.txt'
31+
// };
32+
33+
// // Callback function is used to deal with response
34+
// var callback = function(response){
35+
// // Continuously update stream with data
36+
// var body = '';
37+
// response.on('data', function(data) {
38+
// body += data;
39+
// });
40+
41+
// response.on('end', function() {
42+
// // Data received completely.
43+
// console.log(body);
44+
// });
45+
// }
46+
// // Make a request to the server
47+
// var req = http.request(options, callback);
48+
// req.end();

server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ http.createServer(function(req,res){
2121
res.write(data.toString());
2222
}
2323
res.end();
24-
2524
})
2625

2726
}).listen(1234);

0 commit comments

Comments
 (0)