Closed ddobric closed 7 years ago
Hi @ddobric - I think you are on the right track. Which library are you using? I was able to test the following successfully with hyco-ws
.
var wss = WebSocket.createRelayedServer(
{
server : WebSocket.createRelayListenUri(ns, path),
token: WebSocket.createRelayToken('http://' + ns, keyrule, key)
},
function(ws) {
console.log('connection accepted');
ws.onmessage = function(event) {
console.log('onmessage: ' + event.data);
ws.send('message received: ' + event.data);
};
ws.on('close', function() {
console.log('connection closed');
});
}
);
The other thing to keep in mind here is that you will then have to add the following to your sender application if you want to see anything on the other side.
ws.onmessage = function(event) {
console.log('onmessage: ' + event.data);
};
Hi @jtaubensee ,
I used exactly the same lib.
const WebSocket = require('hyco-ws');
var wss = WebSocket.createRelayedServer(
{
server : WebSocket.createRelayListenUri(ns, path),
token: WebSocket.createRelayToken('http://' + ns, keyrule, key)
},
function (ws) {
console.log('connection accepted');
ws.onmessage = function (event) {
console.log("RCV " + event.data);
ws.send("HELLO", function(err){
console.log(" send failed :(" ); ****
});
};
ws.on('close', function () {
console.log('connection closed');
});
ws.on('open', function () {
console.log('connection open');
});
});
console.log('listening');
wss.on('error', function(err) {
console.log('error' + err);
});
}
This code fails in line marked with '***'. 'err' argument is undefined. This shouldn't be the case. Btw. the sender side is .NET (hyco-relay) code. Due the broker in the middle, this shouldn't have an impact, but it might be useful information.
?
@ddobric - can we continue this in #12? I mean is there anything else that you are looking for regarding a sample?
Hi @jtaubensee , Yes, the sample provided above does not send messages back to relay.
my issue here is that following code simply fails:
ws.send("HELLO", function(err){
console.log(" send failed :(" );
});
In #12 we can follow missing error object.
OK, so I will close this issue and we can discuss the missing error object in #12. Thanks.
Hi John, didn't get this. I have two issues: 1) #12 is right place for missing object. 2) However, issue here is that send does not work.
Again I'll ask how do you know the send is broken? Perhaps there's a bug on the other side in processing what was sent?
I know because, it enters in on-error function and message is not received on the receiver (in this case, listener on the client side).
ws.send("HELLO", function(err){
console.log(" send failed :(" );
});
As I pointed out in my comment on issue 12 this callback is invoked for successful sends as well.
Hi all,
looking for a sample, which demonstrates how listener can response to received message. For example, following code fails:
Not sure if this the right way to do it. Unfortunately, the code above fails with 'unknown' error.
Thanks Damir