By using the HTML/JS code below, I have been able to successfully connect to my SignalR 2.0 hub when both the HTML/JS and hub are on the same server.
<!DOCTYPE html>
<html>
<head>
<title>Test SignalR 2.0</title>
<style type="text/css">
.container {
background-color: #99CCFF;
border: thick solid #808080;
padding: 20px;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<input type="text" size=100 id="message" />
<input type="button" id="sendmessage" value="Send" />
</div>
<ul id="discussion"></ul>
<!--Script references. -->
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-2.0.3.min.js"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
//Instantiating Hub-Class
var srv = $.connection.pvHub;
// Definition of function called by HUB (Server)
srv.client.receiveData = function (message) {
var encodedMsg = $('<div />').text(message).html();
$('#discussion').append('<ul>' + encodedMsg + '</ul><br>');
};
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// call HUB function (on Server)
srv.server.getBnoData($('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
</script>
Now, I am attempting to connect to the hub with the same HTML/JS file located on a client's machine. However, I have not been successful. It seems like there may be some issues with the hub proxy and the URL of my hub during the connection instantiation and start process. I am unsure how to resolve this problem specifically.
Any suggestions or ideas?
Thank you.