Click here to Skip to main content
15,507,755 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have recently heard about signalR. I want to display Realtime data on web application. I have a console application in which receives Realtime data from a device and sends on udp port. This udp data sent by console application should be displayed in web browsers in Realtime. After exploring on internet I found a project on this forum only which displays server system time on web page. But I want to modify it to receive my Udp data from console application. After modification of ClockHub.cs I get error " System.Net.Sockets.SocketException: 'Only one usage of each socket address (protocol/network address/port) is normally permitted'  Please suggest a solution so that I may display the data received from console application on web page of a web application

The original code was taken from Real Time Clock using SignalR[^]

<pre lang="Javascript">var countryZone = "Bangladesh Standard Time";
$(document).ready(function () {
    var hubProxy = $.connection.clockHub;
    hubProxy.client.setTime = function (time) {
    $.connection.hub.start().done(function () {
        setInterval(function () {
        }, 1000);
function select_country() {
    countryZone = $("#lstCountry").val();

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace RealTimeClock.App_Code
    public class ClockHub : Hub
        public void getTime(string countryZone)
           // TimeZone currentZone = TimeZone.CurrentTimeZone;
          //  DateTime currentDate = DateTime.Now;
           // DateTime currentUTC = currentZone.ToUniversalTime(currentDate);
           // TimeZoneInfo selectedTimeZone = TimeZoneInfo.FindSystemTimeZoneById(countryZone);
           // DateTime currentDateTime = TimeZoneInfo.ConvertTimeFromUtc(currentUTC, selectedTimeZone);
             //My modified code to receive udp data from console application
UdpClient receivingUdpClient = new UdpClient(11000); 
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);            
         Clients.Caller.setTime(returnData );

What I have tried:

To display data on web page using signalR

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