Skip to content

Commit 5ac52db

Browse files
committed
get basic connection as a POC. Yay, it works
1 parent f8096d5 commit 5ac52db

File tree

2 files changed

+73
-15
lines changed

2 files changed

+73
-15
lines changed

frame.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,55 @@
1+
var sys = require('sys');
2+
13
function Frame() {
24
this.connected = false;
5+
this.sock = '';
6+
this.command = '';
7+
this.headers = '';
8+
this.body = '';
39

4-
this.connect = function (sock) {
10+
this.stomp_connect = function (sock) {
11+
this.sock = sock;
512
this.connected = true;
6-
console.log('connected');
13+
var args = Array();
14+
var headers = Array();
15+
16+
args['command'] = 'CONNECT';
17+
args['headers'] = headers;
18+
frame_to_send = this.build_frame(args);
19+
this.send_frame(frame_to_send);
20+
console.log('connected to stomp');
21+
return this;
22+
};
23+
24+
this.build_frame = function(args, want_receipt) {
25+
this.command = args['command'];
26+
this.headers = args['headers'];
27+
this.body = args['body'];
28+
if (want_receipt) {
29+
receipt_stamp = Math.floor(Math.random()*10000000+1);
30+
this.headers['receipt'] = "-"
31+
console.log(want_receipt);
32+
}
33+
return this;
34+
};
35+
36+
this.as_string = function() {
37+
command = this.command;
38+
headers = this.headers;
39+
body = this.body;
40+
header_strs = Array();
41+
42+
for (var header in headers) {
43+
header_strs.push(header + ':' + headers[header] + '\n');
44+
}
45+
46+
frame = command + '\n' + header_strs.join() + '\n' + body + '\x00';
47+
48+
return frame;
49+
};
50+
51+
this.send_frame = function(frame) {
52+
this.sock.write(frame.as_string());
753
};
854
};
955

stomp.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,36 @@ function Stomp(port, host) {
99
this.connect = function() {
1010
port = this.port;
1111
host = this.host;
12+
frame = this.frame;
13+
1214
console.log('Connecting to ' + host + ':' + port);
13-
net.createConnection(function (port, host) {
14-
stream.on('connect', function () {
15-
console.log('connected');
16-
this.frame.connect(stream);
17-
});
18-
stream.on('data', function (data) {
19-
stream.write(data);
20-
});
21-
stream.on('end', function () {
22-
stream.write('goodbye\r\n');
23-
stream.end();
24-
});
15+
client = net.createConnection(port, host);
16+
console.dir(client);
17+
18+
client.addListener('connect', function () {
19+
console.log('connected to socket');
20+
connected_frame = frame.stomp_connect(client);
21+
console.dir(connected_frame);
22+
});
23+
client.addListener('data', function (data) {
24+
console.log("Got: " + data);
25+
console.dir(connected_frame);
26+
});
27+
client.addListener('end', function () {
28+
console.log('goodbye');
29+
});
30+
client.addListener('error', function (error) {
31+
console.log(error);
32+
console.log("error");
33+
});
34+
client.addListener('close', function (error) {
35+
console.log("disconnected");
2536
});
2637
};
2738
}
2839
stomp = new Stomp(61613, 'localhost');
40+
stomp.connect();
2941

30-
console.dir(stomp.connect());
42+
console.dir(stomp);
3143

3244
module.exports = Stomp;

0 commit comments

Comments
 (0)