|
-
May 30th, 2013, 03:16 PM
#1
Thread Starter
New Member
[RESOLVED] SignalR and VB/Asp.Net
Has anyone spent much time working with signalR in a VB/ASP.Net environment?
I'm working on a project for work and I am having one heck of a time wrapping my head around signalR since every tutorial is C# and JavaScript.
I've spent the years here at work adding on to our corporate intranet extracting data from our MS SQL database that is mostly populated by our ERP. Through traditional t-sql statements on an internal website I display different forms, and mix in a little Crystal reports as well.
What I've been tasked to do is put a computer monitor at 8 different locations around the plant in different departments. I'll be using some old pc stock to have each station look at a single page on our intranet. What they want to show is a few different items on each screen. RSS news feeds, weather report but most important will be messages entered by department heads about company news, announcements and production scheduling.
So I've set up a couple of simple tables in our database and each department head will use CKEditor on a secure webpage to enter simple html messages. The department head will be able to assign play order and a display duration for each message in seconds depending on how large the message is. There will be a mix of both company wide, and department specific messages displayed on each screen.
So I'm using a URL query string to assign a location for each client when they first visit the page on boot-up.
So now, I'm just looking to set up signalR to push content to each department computer (client) and have it display for the time duration set and as the day progresses have new department and company wide messages show up on the screens.
I'm not looking for someone to write this for me, I'm just looking for a starting point that makes sense. My VB programming skills are at an intermediate level, maybe slightly above.
-
May 30th, 2013, 06:03 PM
#2
Re: SignalR and VB/Asp.Net
Weather you use VB or C# is irrelevant, you would still have to use javascript/jquery in your page. Javascript is required to communicate with the SignalR hub (if you are using hubs).
-
May 30th, 2013, 06:59 PM
#3
Thread Starter
New Member
Re: SignalR and VB/Asp.Net
 Originally Posted by Serge
Weather you use VB or C# is irrelevant, you would still have to use javascript/jquery in your page. Javascript is required to communicate with the SignalR hub (if you are using hubs).
I realize that, I guess I should have said VB and JavaScript. The problem I seem to be having is every tutorial that I read or try is outdated, very convoluted and each one seems to have a lot of different code that apparently has the same result.
I'm kind of looking for the simplest of simplest VB/JavaScript/Jquery example. I can likely build upon it from there.
-
May 30th, 2013, 08:26 PM
#4
Thread Starter
New Member
Re: SignalR and VB/Asp.Net
So I've made some progress, for anyone that happens across this post and is in the same state I was I've finally begun to make a little sense of signalR and VB.
Here is my send.aspx page
HTML Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="send.aspx.vb" Inherits="signalR_send" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../Scripts/jquery-2.0.0.min.js"></script>
<script src="../Scripts/jquery.signalR-1.1.1.min.js"></script>
<script type="text/javascript" src="../Scripts/json2.min.js"></script>
<script type="text/javascript" src="../signalr/hubs"></script>
<script type="text/javascript">
var conn;
$(function () {
conn = $.connection.messageHub;
function SendMessage() {
conn.server.receiveMessage($("#msgToSend").val());
return false;
}
$.connection.hub.start().done($('#sendMessageBtn').click(SendMessage));
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Recieving Page</h3>
<asp:TextBox ID="msgToSend" runat="server"></asp:TextBox><asp:Button ID="sendMessageBtn" runat="server" Text="Send Message" />
</div>
</form>
</body>
</html>
And here is my receive.aspx page
HTML Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="recieve.aspx.vb" Inherits="signalR_recieve" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../Scripts/jquery-2.0.0.min.js"></script>
<script src="../Scripts/jquery.signalR-1.1.1.min.js"></script>
<script type="text/javascript" src="../Scripts/json2.min.js"></script>
<script type="text/javascript" src="../signalr/hubs"></script>
<script type="text/javascript">
var conn;
$(function ()
{
conn = $.connection.messageHub;
conn.client.AcceptMessage = function (message)
{
$('#messages').empty();
$('#messages').append(message);
};
$.connection.hub.start().done();
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Recieving Page</h3>
<asp:TextBox ID="msgToSend" runat="server"></asp:TextBox><asp:Button ID="sendMessageBtn" runat="server" Text="Send Message" />
<br />
<asp:Label ID="messages" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
Next I have my Global.asax page.
Code:
<%@ Application Language="VB" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Routing" %>
<%@ Import Namespace="Microsoft.AspNet.SignalR" %>
<%@ Import Namespace="System.Web.SessionState" %>
<%@ Import Namespace="System.Web.HttpApplication" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
RouteTable.Routes.MapHubs()
End Sub
'Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' ' Code that runs on application shutdown
'End Sub
'Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' ' Code that runs when an unhandled error occurs
'End Sub
'Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' ' Code that runs when a new session is started
'End Sub
'Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' ' Code that runs when a session ends.
' ' Note: The Session_End event is raised only when the sessionstate mode
' ' is set to InProc in the Web.config file. If session mode is set to StateServer
' ' or SQLServer, the event is not raised.
'End Sub
</script>
Then my MessageHub VB class.
Code:
Imports Microsoft.VisualBasic
Imports System
Imports System.Web
Imports Microsoft.AspNet.SignalR
Public Class MessageHub
Inherits Hub
Public Sub ReceiveMessage(Message As String)
Me.Clients.All.AcceptMessage(Message)
End Sub
End Class
Putting this all together I can have my send page open on my development server and my receive page open on an attached client. You could just have both pages open on your development computer. Anything I type in the textbox and send appears on the receive.aspx page. Make sure you've obviously run your NuGet and installed the signalR items.
-
May 31st, 2013, 06:52 AM
#5
Thread Starter
New Member
Re: SignalR and VB/Asp.Net
I'm now trying to take what I've got going and instead of sending from the send.aspx page directly to the receive.aspx through the page scripts I'd like to pass the message from the textbox on the send page to codebehind and from there broadcast to the receive page.
Can anyone share any wisdom or help me out here?
Last edited by Rivelyn; May 31st, 2013 at 07:42 AM.
-
Jun 2nd, 2013, 06:41 PM
#6
Thread Starter
New Member
Re: SignalR and VB/Asp.Net
Update, no update. Still struggling with the server side sending through signalR. Is there seriously no one that has done this with vb.net yet?
-
Jun 4th, 2013, 12:43 PM
#7
Thread Starter
New Member
Re: SignalR and VB/Asp.Net
This has been an uphill battle, I'm seriously disappointed in the lack of VB information for signalR.
-
Jun 5th, 2013, 03:13 AM
#8
Re: [RESOLVED] SignalR and VB/Asp.Net
Hello,
Have you tried the jabbr chat room of SignalR. That is probably your best bet in terms of getting specific answers to the questions that you have.
Gary
-
Jun 5th, 2013, 07:03 AM
#9
Thread Starter
New Member
Re: [RESOLVED] SignalR and VB/Asp.Net
Through a lot of trial and error I have succeeded in sending a message from the server to a client using VB.Net and signalR.
What amazes me is the amount of "Her's how you do it" posts out there that doesn't work...lol
SendMessage is located within MessageHub
Code:
Public Shared Sub SendMessage(message As String)
Dim context As IHubContext = GlobalHost.ConnectionManager.GetHubContext(Of MessageHub)()
context.Clients.All.AcceptMessage(message)
End Sub
The on my send.aspx page I removed the javascript and just put in a vb button click event in the code behind page like so.
Code:
Protected Sub sendMessageBtn_Click(sender As Object, e As EventArgs) Handles sendMessageBtn.Click
MessageHub.SendMessage(msgToSend.Text)
End Sub
the msgToSend is just a text box.
-
Jun 5th, 2013, 07:44 AM
#10
Re: [RESOLVED] SignalR and VB/Asp.Net
One thing to bear in mind is that SignalR is not a "guaranteed" message delivery system, it simply sends a message to all connected clients. If for some reason an application closes, that client won't get it. As long as you are happy with that.
Gary
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|