Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In websocket programming I am getting the value of IsWebSocketRequest false. I want to know why it is returning value false. ‍ ‍ ‍
Here's my JavaScript code.

What I have tried:

$('#openButton').click(function() {

try {

username = $('#txtuserid').val();
var url = "ws://" + window.location.host + '/api/Values?userid=' + username;
demoService = new WebSocket(url);
console.log(url);
demoService.onopen = function() {
$('#divmsg').append('Connection Opened
');
}

demoService.onmessage = function(message) {
var md = message.data;
if (md.substring(0, 5) == 'user:') {
$('#txloginuser').val(md.replace('user:', ''));
} else if (md.substring(0, 4) == 'key:') {
$('#txuserkey').val(md.replace('key:', ''));
} else {
$('#divmsg').append(message.data + "
");
}
}

demoService.onclose = function() {
try {
$('#divmsg').append("Connection Closed" + "
");
$('#txloginuser').val('');
$('#txuserkey').val('');
$('#txuserid').val('');
$('#divmsg').empty();
} catch (ex) {
alert(ex);
}
}


demoService.onerror = function(error) {
$('#divmsg').append(error.data + "
");
}
} catch (ex) {
alert(ex);
}
});
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900