获取客户端真实IP
/// <summary> /// 取得客户端真实IP。如果有代理则取第一个非内网地址 /// </summary> public static string GetIPAddress{get{var result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];if (!string.IsNullOrEmpty(resu…
/// <summary> /// 取得客户端真实IP。如果有代理则取第一个非内网地址 /// </summary> public static string GetIPAddress{get{var result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];if (!string.IsNullOrEmpty(resu…
相关视频教程 https://www.bilibili.com/video/BV1LM4y1V7Am(如果不会请看我录制的视频教程)1、在Startup类里面 注册服务,如下图services.AddSingletonIHttpContextAccessor, HttpContextAccessor();2、在控制器里面获取ip 方法如下HttpContextAccessor context = new Ht…
MQTT用的就是TCP/IP协议 ,Socket通讯,MQTT定义了一套自己的数据传输格式。 在这里我们引用的是MQTTnet.dll,它将数据的传输格式、数据监听和数据转发封装了,我们只要调用就可以。开源库地址:https://github.com/chkr1011/MQTTnet对应文档:https://github.com/chkr1011/MQT…
nginx.conf配置文件部分信息server { listen 80; server_name www.luofenming.com; location / { proxy_pass http://localhost:8711; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header …
1、先启动服务端 IP和端口都为服务端 2、客户端连接到服务端 IP和端口都为服务端 3、客户端发送信息到服务端 以下是原理图以下是Socket服务端核心代码//原创来自 http://www.luofenming.com/show.aspx?id=ART2018120700001/// <summary>/// 创建Scoket 服务端/// </…
Socket服务端可能有一些长期连接的Socket客户端,并且长期不发送数据到服务端,这样很浪费服务端资源。下面代码是服务端主动断开无用的Socket客户端/// summary/// 接收客户端发来的信息/// /summarystatic void ServerRecMsg(object socketClientPara){Socket socke…
.net Core微服务架构之集群,服务注册和发现,客户端--多服务实例--Consul完成服务的注册与发现,框架结构图如下Nuget下载Consul,服务注册核心代码(写了一个扩展方法) public static class ConsuHelper {public static void ConsuRegist(this IConfiguration configuration){tr…