I have a project on vb.net that previously did not have SignalR . I did the whole process of importing libraries with Nuget , I manually created the classes necessary for its operation, but I have not gotten it to work.
I simply try to send a notification to the clients from the server when a certain event occurs.
This would be the server part:
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports Microsoft.AspNet.SignalR
Imports Owin
Public Class Startup
Public Sub Configuration(app As IAppBuilder)
' Any connection or hub wire up and configuration should go here
app.MapSignalR()
End Sub
End Class
Public Class MessageHub
Inherits Hub
Public Shared Contexto As IHubContext
Public Sub EnviaMensaje(mensaje As String)
Dim context = GlobalHost.ConnectionManager.GetHubContext("MessageHub")
context.Clients.All.EnviaMensaje(mensaje)
End Sub
End Class
Public Class Mensaje
Public Usuario As String
Public Mensaje As String
End Class
Partial Class Pisos_Pisos
Inherits System.Web.UI.MasterPage
Public Shared GroupEP As IPEndPoint = Nothing
Private HiloDeEscucha As Threading.Thread
Private IpLocal As IPAddress
Public Shared Escuchador As UdpClient = Nothing
Public Shared TablaEventos As New EventosDS.COM_EventosDataTable
Public Shared AdaptadorEventos As New EventosDSTableAdapters.COM_EventosTableAdapter
Private AdaptadorUsuario As UsuariosDSTableAdapters.Web_UsuariosTableAdapter
Private TablaUsuario As UsuariosDS.Web_UsuariosDataTable
Public Shared MessageHub As New MessageHub
Public Property Usuario() As String
Get
Return lblUsuario.Text
End Get
Set(ByVal value As String)
lblUsuario.Text = value
End Set
End Property
Public Property RutaFoto() As String
Get
Return Image1.ImageUrl
End Get
Set(ByVal value As String)
Image1.ImageUrl = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim AutentCookie As HttpCookie
Dim Ticket As FormsAuthenticationTicket
Dim strTicket As String
Dim strRuta As String
Dim strPerfil As String
AutentCookie = Request.Cookies(FormsAuthentication.FormsCookieName)
Ticket = FormsAuthentication.Decrypt(AutentCookie.Value)
Usuario = Ticket.Name
strTicket = Ticket.UserData.Trim
strRuta = strTicket.Substring(0, strTicket.IndexOf(";")).Trim
strPerfil = strTicket.Substring(strRuta.Length + 1).Trim
If strPerfil = "ADMINISTRADOR" Then
LBSubGobernantas.Visible = True
LBDiariosSubG.Visible = True
Else
LBSubGobernantas.Visible = False
LBDiariosSubG.Visible = False
End If
RutaFoto = "~/Images/Personal/" & strRuta
lblAhora.Text = "Inicio de conexión: " & Now.ToString
IniciarEscucha()
End Sub
Protected Sub LBCerrarSesion_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LBCerrarSesion.Click
FormsAuthentication.SignOut()
Response.Redirect("~\Default.aspx", True)
End Sub
Public Sub IniciarEscucha()
If GroupEP Is Nothing Then
GroupEP = New IPEndPoint(IPAddress.Any, 19500)
End If
HiloDeEscucha = New Thread(AddressOf Escuchar)
HiloDeEscucha.Start()
End Sub
Private Sub Escuchar()
Dim mensaje As String = ""
Try
Escuchador = New UdpClient(19500)
Catch excSock As System.Net.Sockets.SocketException
If Escuchador Is Nothing Then
Exit Sub
End If
End Try
While True
Try
Dim Bytes As Byte() = Escuchador.Receive(GroupEP)
mensaje = System.Text.Encoding.Default.GetString(Bytes)
Catch e1 As ThreadAbortException
Exit While
Catch e2 As Exception
End Try
If mensaje.Contains("RACK") And Not mensaje.Contains(My.Computer.Name) Then
If mensaje.Contains("|") Then
MessageHub.EnviaMensaje(mensaje.Substring(mensaje.IndexOf("|") + 1))
End If
End If
End While
End Sub
End Class
The client part (javascript), would be the following:
Palm Oasis - Management - Floors
<script src="..." ></script>
<script src="..."></script>
<script src="..."></script>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link href=".." rel="stylesheet" type="text/css" />
<style type="text/css">
.style1
{
width: 730px;
text-align: left;
}
.style2
{
height: 49px;
}
.style3
{
width: 730px;
text-align: left;
height: 49px;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
var proxy = $.connection.MessageHub;
proxy.client.EnviaMensaje = function (mensaje) {
document.getElementById('player').play();
$("#lblNotificacion").text(mensaje);
}
$.connection.hub.start().done(function () { $("#lblNotificacion").text("Conexión establecida!") });
}
);
</script>
(...)
If I execute the project, I have the following error on the client side:
jQuery.Deferred exception: Cannot read property 'client' of undefined TypeError: Cannot read property 'client' of undefined
at HTMLDocument.<anonymous> (...)
at mightThrow (...)
at process () undefined
I've been stuck for two weeks and searching the Internet. It is very likely that it is silly, but I can not find the solution. Could someone help me?