UDP receive in asp.net web application SignalR

cdeo 1 Reputation point
2021-02-10T17:42:34.933+00:00

I want to receive a realtime data in a web application and display that realtime data in web form. I have heard about the signalR. I tried to put UDP receive codes as shown below in the hub class. But it gives error . Please suggest any solution so that in web application I receive udp packet on some port and push that data to clients in brouser in realtime.

UdpClient receivingUdpClient = new UdpClient(11000);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,208 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Wang-MSFT 1,051 Reputation points
    2021-02-11T05:49:25.74+00:00

    Hi, @cdeo ,

    SignalR uses Websockets to communicate between the clients and the server. SignalR allows messages to be sent to all connections associated with a specific user, as well as to named groups of connections(like UDP broadcast).

    Users in SignalR

    public Task SendPrivateMessage(string user, string message)  
    {  
        return Clients.User(user).SendAsync("ReceiveMessage", message);  
    }  
    

    Groups in SignalR

    public async Task AddToGroup(string groupName)  
    {  
        await Groups.AddToGroupAsync(Context.ConnectionId, groupName);  
      
        await Clients.Group(groupName).SendAsync("Send", $"{Context.ConnectionId} has joined the group {groupName}.");  
    }  
    

    ---
    If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Michael Wang

    0 comments No comments