I have recently heard about signalR. I want to display Realtime data on web application. I have a console application in asp.net 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
Client.js <pre lang="Javascript">var countryZone = "Bangladesh Standard Time"; $(document).ready(function () { var hubProxy = $.connection.clockHub; hubProxy.client.setTime = function (time) { $('#clock').html(time); }; $.connection.hub.start().done(function () { setInterval(function () { hubProxy.server.getTime(countryZone); }, 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 ); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)