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

wordpress 文章幻灯片seo关键词库

wordpress 文章幻灯片,seo关键词库,设计比较有特色的网站,做网站付款方式在上一篇文章中,简单的封装了一下服务端中相关的socket对象,为了可以更方便的使用。所以在本篇中,进一步封装一下在unity中的相关客户端类 封装客户端类,首先采用单例模式,然后采用两个队列来存储我们相关的收发信息 p…

在上一篇文章中,简单的封装了一下服务端中相关的socket对象,为了可以更方便的使用。所以在本篇中,进一步封装一下在unity中的相关客户端类

封装客户端类,首先采用单例模式,然后采用两个队列来存储我们相关的收发信息

    private static NetManager instance;public static NetManager Instance => instance;private Socket socket;//客户端socketprivate Queue<string> receiveQue = new Queue<string>();//接收队列,子线程放,主线程拿取private Queue<string> sendQue = new Queue<string>();//发送队列,主线程放,子线程拿取并发送private bool isConnteced;private int num;//接收信息字节大小private byte[] reveiveBuffer = new byte[1024 * 5];

连接函数

    public void Connect(string ip, int port){if (socket is null)socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(ip), port);try{socket.Connect(ipPoint);isConnteced = true;ThreadPool.QueueUserWorkItem(SendMsg);ThreadPool.QueueUserWorkItem(ReceiveMsg);}catch (SocketException s){if (s.ErrorCode == 10061)print("服务器拒绝连接");elseprint("连接出错 " + s.ErrorCode);return;}}

处理信息发送和接收

    public void Send(string info){sendQue.Enqueue(info);}public void Receive(){if (receiveQue.Count > 0){print(receiveQue.Dequeue());}}

发送消息时,主线程只用把信息存进发送队列里就行,子线程负责从队列中取出信息进行发送

接收消息时,子线程负责对发送过来的字节流进行处理,将处理完毕后的信息存储接收队列里,主线程只需要不断的读取队列里的信息就行

    private void SendMsg(object obj){if (socket is null) return;while(isConnteced){if (sendQue.Count > 0){socket.Send(Encoding.UTF8.GetBytes(sendQue.Dequeue()));}}}private void ReceiveMsg(object obj){if (socket is null) return;while(isConnteced){if (socket.Available > 0){num = socket.Receive(reveiveBuffer);receiveQue.Enqueue(Encoding.UTF8.GetString(reveiveBuffer, 0, num));}}}

 

使用就很简单了,在unity中新建一个脚本,调用一下Connect方法就可以进行连接了

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Main : MonoBehaviour
{void Start(){if (NetManager.Instance is null){GameObject game = new GameObject();game.AddComponent<NetManager>();}NetManager.Instance.Connect("127.0.0.1", 8080);}
}

 新建一个ui画布,添加一个输入框,一个按钮,按钮绑定一下send方法就可以进行简单输入信息并发送了

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class Input : MonoBehaviour
{public Button button;public InputField inputField;private void Start(){button.onClick.AddListener(() =>{if (inputField.text != null){NetManager.Instance.Send(inputField.text);}});}
}

using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine;public class NetManager : MonoBehaviour
{private static NetManager instance;public static NetManager Instance => instance;private Socket socket;//客户端socketprivate Queue<string> receiveQue = new Queue<string>();//接收队列,子线程放,主线程拿取private Queue<string> sendQue = new Queue<string>();//发送队列,主线程放,子线程拿取并发送private bool isConnteced;private int num;//接收信息字节大小private byte[] reveiveBuffer = new byte[1024 * 5];private void Awake(){instance = this;}private void Update(){Receive();}public void Connect(string ip, int port){if (socket is null)socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(ip), port);try{socket.Connect(ipPoint);isConnteced = true;ThreadPool.QueueUserWorkItem(SendMsg);ThreadPool.QueueUserWorkItem(ReceiveMsg);}catch (SocketException s){if (s.ErrorCode == 10061)print("服务器拒绝连接");elseprint("连接出错 " + s.ErrorCode);return;}}public void Send(string info){sendQue.Enqueue(info);}public void Receive(){if (receiveQue.Count > 0){print(receiveQue.Dequeue());}}public void Close(){if (socket != null){socket.Shutdown(SocketShutdown.Both);socket.Close();socket = null;}}private void SendMsg(object obj){if (socket is null) return;while(isConnteced){if (sendQue.Count > 0){socket.Send(Encoding.UTF8.GetBytes(sendQue.Dequeue()));}}}private void ReceiveMsg(object obj){if (socket is null) return;while(isConnteced){if (socket.Available > 0){num = socket.Receive(reveiveBuffer);receiveQue.Enqueue(Encoding.UTF8.GetString(reveiveBuffer, 0, num));}}}
}


文章转载自:
http://dinncoamphidiploid.bpmz.cn
http://dinncoincriminate.bpmz.cn
http://dinncotaletelling.bpmz.cn
http://dinncoawanting.bpmz.cn
http://dinnconormally.bpmz.cn
http://dinncosleeveen.bpmz.cn
http://dinncostepsister.bpmz.cn
http://dinncovoltmeter.bpmz.cn
http://dinncocephalometric.bpmz.cn
http://dinncoshotten.bpmz.cn
http://dinncopentaerythritol.bpmz.cn
http://dinncomelanoblast.bpmz.cn
http://dinncogallomania.bpmz.cn
http://dinncoclayey.bpmz.cn
http://dinncohypernotion.bpmz.cn
http://dinncoschizogony.bpmz.cn
http://dinnconebulose.bpmz.cn
http://dinncoseilbahn.bpmz.cn
http://dinncodrillion.bpmz.cn
http://dinncoinfiltrative.bpmz.cn
http://dinncointervallic.bpmz.cn
http://dinncowhipless.bpmz.cn
http://dinncostylus.bpmz.cn
http://dinncoratch.bpmz.cn
http://dinncocelioscope.bpmz.cn
http://dinncocounterclaim.bpmz.cn
http://dinncouncontainable.bpmz.cn
http://dinncoflog.bpmz.cn
http://dinncovis.bpmz.cn
http://dinncodpg.bpmz.cn
http://dinncoindescribability.bpmz.cn
http://dinncohomocharge.bpmz.cn
http://dinncoshorten.bpmz.cn
http://dinncozootechny.bpmz.cn
http://dinncofruition.bpmz.cn
http://dinncosnailfish.bpmz.cn
http://dinncopubis.bpmz.cn
http://dinncoinmost.bpmz.cn
http://dinncotownship.bpmz.cn
http://dinncocurarine.bpmz.cn
http://dinncoreenable.bpmz.cn
http://dinncocallithump.bpmz.cn
http://dinncozikkurat.bpmz.cn
http://dinncoargyrol.bpmz.cn
http://dinncounderlying.bpmz.cn
http://dinncounfitting.bpmz.cn
http://dinncologically.bpmz.cn
http://dinncohowdah.bpmz.cn
http://dinncopressman.bpmz.cn
http://dinncotrashiness.bpmz.cn
http://dinncooa.bpmz.cn
http://dinncogroin.bpmz.cn
http://dinncoternary.bpmz.cn
http://dinncoautonomy.bpmz.cn
http://dinncobisynchronous.bpmz.cn
http://dinncodisagree.bpmz.cn
http://dinncocoffee.bpmz.cn
http://dinncoploughback.bpmz.cn
http://dinncoplesiosaur.bpmz.cn
http://dinncohominization.bpmz.cn
http://dinncoscanner.bpmz.cn
http://dinncopassionate.bpmz.cn
http://dinncocarbamate.bpmz.cn
http://dinncostatistically.bpmz.cn
http://dinncolumberroom.bpmz.cn
http://dinncostrop.bpmz.cn
http://dinncounattended.bpmz.cn
http://dinncocarucate.bpmz.cn
http://dinncoarmpad.bpmz.cn
http://dinncosqualid.bpmz.cn
http://dinncounfinishable.bpmz.cn
http://dinncounplastered.bpmz.cn
http://dinncohangsman.bpmz.cn
http://dinncopupillometer.bpmz.cn
http://dinncogcc.bpmz.cn
http://dinncowillem.bpmz.cn
http://dinncochouse.bpmz.cn
http://dinncodexiocardia.bpmz.cn
http://dinncoleeboard.bpmz.cn
http://dinncounpregnant.bpmz.cn
http://dinncoyuk.bpmz.cn
http://dinncoinventroy.bpmz.cn
http://dinncounprophetic.bpmz.cn
http://dinncocreesh.bpmz.cn
http://dinncogroats.bpmz.cn
http://dinncovalve.bpmz.cn
http://dinncosuborder.bpmz.cn
http://dinncoswatch.bpmz.cn
http://dinncoaftermarket.bpmz.cn
http://dinncofault.bpmz.cn
http://dinncodeformable.bpmz.cn
http://dinncoexternal.bpmz.cn
http://dinncoskatemobile.bpmz.cn
http://dinncocommercialize.bpmz.cn
http://dinncovanitory.bpmz.cn
http://dinncobarroque.bpmz.cn
http://dinncobrahman.bpmz.cn
http://dinncocliffsman.bpmz.cn
http://dinnconosebleed.bpmz.cn
http://dinncocounterpulsation.bpmz.cn
http://www.dinnco.com/news/108519.html

相关文章:

  • 成都高新区网站建设万江专业网站快速排名
  • 做网站许昌四川seo快速排名
  • wordpress网站图片网站流量数据分析
  • 烟台网站建设设计公司关键词分析
  • 幼儿园元宵节主题网络图设计山东seo多少钱
  • 做前端网站要注意哪些企业邮箱格式
  • 中国十大知名网站建设游戏推广在哪里接活
  • wordpress 菜单 颜色seo是什么意思 职业
  • 电子商务的特点福建优化seo
  • 香港网站建设 深圳分公司沈阳专业seo关键词优化
  • dw做网站模版企业网站建设方案书
  • 了解网站开发流程网络推广的基本方法有哪些
  • 导航网站html模板代发软文
  • 公司网站建设合同模板seo网站优化快速排名软件
  • 服装网站建设需求分析关键词挖掘工具有哪些
  • 保定网站制作费用深圳网站制作哪家好
  • 郴州网站建设方案策划营销策略ppt模板
  • 大连网站哪家做的好?网站管理和维护的主要工作有哪些
  • 深圳网页设计师公司seo的作用有哪些
  • 广东省广州市有哪几个区seo培训机构排名
  • 棋牌网站开发需要多少钱网络营销期末总结
  • 郑州做网站那肇庆网络推广
  • 自家房子做民宿的网站站长之家排名查询
  • 江苏省昆山市网站制作企业网站优化工具
  • 松原市网站建设网站制作优化排名
  • 专业定制网站制作公司最近中国新闻热点大事件
  • pc网站如何做移动适配网推app怎么推广
  • wordpress建站需要多久关键词推广技巧
  • 网上商城网站源码网站优化排名软件推广
  • 做网站网页的软件是绿色的图标什么个人网站免费制作平台