当前位置: 首页 > news >正文

如何做网站appwordpress 物流信息

如何做网站app,wordpress 物流信息,优购物官方网站下载,品牌建设推荐文章目录 前言相关文章前言设计代码简单使用运行结果 前言 我最近有个需求要写Tcp服务端#xff0c;我发现Tcp服务端的回调函数比较麻烦#xff0c;简化Tcp的服务#xff0c;我打算自己封装一个简单的Tcp服务端。 相关文章 C# TCP应用编程三 异步TCP应用编程 C# Tcpclient… 文章目录 前言相关文章前言设计代码简单使用运行结果 前言 我最近有个需求要写Tcp服务端我发现Tcp服务端的回调函数比较麻烦简化Tcp的服务我打算自己封装一个简单的Tcp服务端。 相关文章 C# TCP应用编程三 异步TCP应用编程 C# Tcpclient Tcplistener 服务器接收多个客户端消息通讯 关于C#Socket断开重连问题 前言 我最近有个Tcp服务端的项目发现TcpListener 服务端官方写起来很麻烦。而且没有回调函数。现在做个简单的服务端封装 设计 #mermaid-svg-MfJRajt4eQGGeIC6 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-MfJRajt4eQGGeIC6 .error-icon{fill:#552222;}#mermaid-svg-MfJRajt4eQGGeIC6 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-MfJRajt4eQGGeIC6 .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-MfJRajt4eQGGeIC6 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-MfJRajt4eQGGeIC6 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-MfJRajt4eQGGeIC6 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-MfJRajt4eQGGeIC6 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-MfJRajt4eQGGeIC6 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-MfJRajt4eQGGeIC6 .marker.cross{stroke:#333333;}#mermaid-svg-MfJRajt4eQGGeIC6 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-MfJRajt4eQGGeIC6 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-MfJRajt4eQGGeIC6 .cluster-label text{fill:#333;}#mermaid-svg-MfJRajt4eQGGeIC6 .cluster-label span{color:#333;}#mermaid-svg-MfJRajt4eQGGeIC6 .label text,#mermaid-svg-MfJRajt4eQGGeIC6 span{fill:#333;color:#333;}#mermaid-svg-MfJRajt4eQGGeIC6 .node rect,#mermaid-svg-MfJRajt4eQGGeIC6 .node circle,#mermaid-svg-MfJRajt4eQGGeIC6 .node ellipse,#mermaid-svg-MfJRajt4eQGGeIC6 .node polygon,#mermaid-svg-MfJRajt4eQGGeIC6 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-MfJRajt4eQGGeIC6 .node .label{text-align:center;}#mermaid-svg-MfJRajt4eQGGeIC6 .node.clickable{cursor:pointer;}#mermaid-svg-MfJRajt4eQGGeIC6 .arrowheadPath{fill:#333333;}#mermaid-svg-MfJRajt4eQGGeIC6 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-MfJRajt4eQGGeIC6 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-MfJRajt4eQGGeIC6 .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-MfJRajt4eQGGeIC6 .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-MfJRajt4eQGGeIC6 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-MfJRajt4eQGGeIC6 .cluster text{fill:#333;}#mermaid-svg-MfJRajt4eQGGeIC6 .cluster span{color:#333;}#mermaid-svg-MfJRajt4eQGGeIC6 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-MfJRajt4eQGGeIC6 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} TcpServerService ShowMsg:打印消息 AddClient_CallBack:新增Tcp客户端回调函数 SendMsg/ReceiveMsg:Tcp客户端发送接受回调 Clients:Tcp客户端集合,连接增加,断开去除 其它函数 代码 public class TcpServeService {public string Ip { get; set; }public int Port { get; set; }public TcpListener Server { get; set; }public ListTcpClient Clients { get; set; }/// summary/// 客户端添加回调函数如果要重写通讯逻辑需要覆盖/// /summarypublic ActionTcpClient AddClient_CallBack { get; set; }public Actionstring ShowMsg { get; set; }/// summary/// 默认自动回复Tcp服务端/// /summary/// param nameip/param/// param nameport/parampublic TcpServeService(string ip, int port){Clients new ListTcpClient();ShowMsg (msg) Console.WriteLine(msg);AddClient_CallBack (client) AutoSendBack(client);this.Ip ip;this.Port port;Server new TcpListener(IPAddress.Parse(ip), port);}/// summary/// Tcp添加Client回调/// /summary/// param namear/paramprivate void DoAcceptTcpclient(IAsyncResult ar){// Get the listener that handles the client request.TcpListener listener (TcpListener)ar.AsyncState;// End the operation and display the received data on // the console.TcpClient client listener.EndAcceptTcpClient(ar);Clients.Add(client);// Process the connection here. (Add the client to a// server table, read data, etc.)ShowMsg($Tcp客户端连接成功,当前连接数{Clients.Count},Id[{client.Client.RemoteEndPoint.ToString()}]);AddClient_CallBack(client);//开启线程用来不断接收来自客户端的数据Server.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpclient), Server);}/// summary/// 移除Tcp客户端/// /summary/// param nameclient/parampublic void RemoveClient(TcpClient client){NetworkStream stream client.GetStream();ShowMsg($Tcp客户端连接断开,当前连接数{Clients.Count},Id[{client.Client.RemoteEndPoint.ToString()}]);stream.Close();client.Close();Clients.Remove(client);}/// summary/// 启动Tcp服务/// /summarypublic void Start(){Server.Start();Server.BeginAcceptTcpClient(new AsyncCallback(DoAcceptTcpclient), Server);ShowMsg($Tcp服务端启动成功!IP[{Ip}],Port[{Port}]);}/// summary/// 返回数据/// /summary/// param nameStr/param/// param nameBytes/parampublic record TcpData(string Str, byte[] Bytes);/// summary/// 同步阻塞读取数据/// /summary/// param nameclient/param/// returns/returnspublic static TcpData ReadMsg(TcpClient client){NetworkStream networkStream client.GetStream();var resBytes new byte[client.ReceiveBufferSize];var num networkStream.Read(resBytes, 0, resBytes.Length);resBytes resBytes.Take(num).ToArray();var resStr UnicodeEncoding.ASCII.GetString(resBytes);if (!IsConnect(client)){throw new Exception(${client.Client.RemoteEndPoint?.ToString()}Tcp连接已断开);}return new TcpData(resStr,resBytes);}/// summary/// 发送Ascll数据/// /summary/// param nametcpClient/param/// param namemsg/parampublic static void SendMsg(TcpClient tcpClient, string msg){byte[] arrSendMsg Encoding.UTF8.GetBytes(msg);SendMsg(tcpClient, arrSendMsg);}/// summary/// Tcp客户端连接是否断开/// /summary/// param nametcpClient/param/// returns/returnspublic static bool IsConnect(TcpClient tcpClient){if (tcpClient.Client.Poll(1, SelectMode.SelectRead) tcpClient.Available 0){return false;}else { return true; }}/// summary/// 发送Bytes[]数据/// /summary/// param nametcpClient/param/// param namemsg/parampublic static void SendMsg(TcpClient tcpClient, byte[] msg){NetworkStream networkStream tcpClient.GetStream();networkStream.Write(msg, 0, msg.Length);}/// summary/// 发送并返回数据/// /summary/// param nametcpClient/param/// param namemsg/param/// returns/returnspublic static TcpData SendAndReceive(TcpClient tcpClient,string msg){SendMsg(tcpClient,msg);return ReadMsg(tcpClient);}public static TcpData SendAndReceive(TcpClient tcpClient, byte[] msg){SendMsg(tcpClient, msg);return ReadMsg(tcpClient);}/// summary/// 默认自动回复异常捕捉/// /summary/// param nametcpClient/param/// param nametimeOut超时时间/param/// returns/returnspublic async Task AutoSendBack(TcpClient tcpClient, int timeOut 10 * 1000){//超时时间tcpClient.ReceiveTimeout timeOut;tcpClient.SendTimeout timeOut;while (true){try{if (!Clients.Contains(tcpClient)){throw new Exception(Tcp客户端已被移除!);}var receive ReadMsg(tcpClient);ShowMsg($TcpClient[{tcpClient.Client.RemoteEndPoint?.ToString()}]:收到数据{receive.Str});SendMsg(tcpClient, receive.Str);}catch (Exception ex){RemoveClient(tcpClient);ShowMsg(发送失败);ShowMsg(ex.Message);}}}}简单使用 //对tcpServeService进行了默认配置默认自动回复自动维护Client集合 TcpServeService tcpServeService new TcpServeService(192.168.100.21, 10003);//如果想要自定义回复需要覆盖AddClient_CallBack函数使用异步任务处理连接 //tcpServeService.AddClient_CallBack ((client) { // Task.Run(() // { // //你的客户端连接异步任务 // }); //});//如果想要打印在Winfrom/WPF的界面覆盖此回调 //tcpServeService.ShowMsg (msg) //{ // //你的消息打印函数 //}; //tcpServeService.Start(); tcpServeService.Start();运行结果
http://www.huolong8.cn/news/77576/

相关文章:

  • 制作好的网页怎么变成网站建材公司网站建设案例
  • 中小型网站有哪些谷歌浏览器网页打不开是什么原因
  • 公司做网站的虚拟机iis网站建设
  • 网站域名更换相应内容网站建设大约多少费用
  • 绍兴网站制作系统六安在线网
  • 上海网站设计图片广元市建设银行网站
  • 如何将aaa云主机做网站企业建网站报价
  • .net 建网站工信部网站备案系统登录
  • 新浪网页打不开外贸网站优化免费渠道
  • 怎样做公司的网站建设微信网站开发视频教程
  • 沈阳网站开发久潍坊免费自助建站模板
  • 南京市建设监理协会网站学院后勤处网站建设方案书
  • 做一个微网站平台百度搜索排行榜
  • 西安免费自助建站模板网站建设项目进度表
  • 山东省城乡与住房建设厅网站江苏网站建设教程
  • 网站专题活动策划方案怎样注册自己的域名
  • 萧山网站制作公司站群网站和做seo那个号
  • 安徽省做网站建e网室内设计网别墅
  • 南昌网站建设过程中国十大进出口公司排名
  • 网络维护网站网络软文投放
  • 科技网站 石家庄温州网站建设制作公司
  • 安徽省住房和城乡建设厅网站领域外包公司不给员工发工资怎么办
  • 公司网站建设是什么意思crm系统管理软件
  • 自助免费网站建设平台工作纪律生活纪律研讨发言
  • 宁德城乡建设部网站新乡seo推广
  • 有什么好的网站做推广的网站建设技术支持包括哪些
  • 给公司做一个网站流程博客 wordpress 登录
  • 北京网站建设企业山西太原网站建设公司
  • 深圳专业建网站公司注册餐饮公司需要什么条件
  • 海口cms建站系统室内设计师联盟网