c# - 如何在 SignalR Hub C# 中接收 UDP 套接字数据
问题描述
我在我的 Web 项目中的 SignalR 中创建了一个集线器。在我的集线器类中,我想接收在端口号 4001 上发送的 udp 数据。请建议通过 udp 套接字接收数据的代码。我尝试使用如下所示的代码接收,但它给出错误“System.Net.Sockets.SocketException:'通常只允许使用每个套接字地址(协议/网络地址/端口)”
时钟集线器.cs
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 getSocketData()
{
// Here I want to receive udp socket data on port 4001
// my code commented here did not work
//UdpClient receivingUdpClient = new UdpClient(11000);
//IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
//Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
//string UDP_Rx_Data= Encoding.ASCII.GetString rceiveBytes);
Clients.Caller.setTime(UDP_Rx_Data);
}
}
}
解决方案
推荐阅读
- r - 找不到绘图函数对象的错误
- javascript - 如何在 Nodejs mocha 中声明一个全局数组?
- c# - C# - 不能在同一源的 WPF 项目中使用 .NET Framework 项目中的类
- canvas - 带有 clearRect 和 AudioContext 的画布清除路径
- ssl - URL 阻止机器人
- python - 为什么 Python 函数返回错误的值?
- css - 如何使用 css 和 html 悬停边框?
- angular - 将可见性设置为隐藏后删除表格行之间的间隙
- mongodb - 当您超出 mongoDB 中的空间限制时发生了什么?
- wordpress - 下订单时触发操作(woocommerce)