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

当富广州网站建设视频号的网站链接

当富广州网站建设,视频号的网站链接,wordpress优化css,聚名网实名认证有风险吗因为需要用到unity和其他的程序交互,其他程序可以提供Udp消息,因此找了合适的相互连接方法。这里直接上代码。 工具类: using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Net; u…

因为需要用到unity和其他的程序交互,其他程序可以提供Udp消息,因此找了合适的相互连接方法。这里直接上代码。

工具类:

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine;
using UnityEngine.Video;public class UdpManager
{public static string m_receivedMessage;static IPEndPoint m_IPEndPoint;static UdpClient m_udpClient;public static void InitializeUdpClient(){m_IPEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080);m_udpClient = new UdpClient(m_IPEndPoint);UdpModel s = new UdpModel(m_udpClient, m_IPEndPoint);m_udpClient.BeginReceive(EndReceive, s);Debug.Log("服务器启动");}//结束得到的信息private static void EndReceive(IAsyncResult ar){try{UdpModel m_UdpModel = ar.AsyncState as UdpModel;if (m_UdpModel != null){UdpClient udpClient = m_UdpModel.m_udpclient;IPEndPoint ip = m_UdpModel.m_ip;Byte[] receiveBytes = udpClient.EndReceive(ar, ref ip);string msg = Encoding.UTF8.GetString(receiveBytes);m_receivedMessage = msg;udpClient.BeginReceive(EndReceive, m_UdpModel); //开始获取}}catch (Exception ex){//处理异常}}//udp模型private class UdpModel{public UdpClient m_udpclient = null;public IPEndPoint m_ip;public UdpModel(UdpClient udpclient, IPEndPoint ip){this.m_udpclient = udpclient;this.m_ip = ip;}}//关闭public static void Close(){if (m_udpClient != null){m_udpClient.Close();m_udpClient = null;}}/// <summary>/// 发送数据/// </summary>/// <param name="obj"></param>public static void SendMessage(string message){UdpClient myUdpClient = new UdpClient();IPEndPoint endpoint;//当前服务器ip和端口号myUdpClient = new UdpClient(new IPEndPoint(IPAddress.Any, 8800));//要发送给的地址和端口号,255.255.255.255表示在这个局域网的所有ipendpoint = new IPEndPoint(IPAddress.Parse("192.168.31.174"), 1180);byte[] bytes = Encoding.UTF8.GetBytes(message);try{myUdpClient.Send(bytes, bytes.Length, endpoint);myUdpClient.Close();}catch (Exception err){Console.Write(err.Message, "发送失败");}finally{myUdpClient.Close();}}
}

需要挂载运行的脚本:

using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.Video;/// <summary>
/// 服务接收生成
/// </summary>
public class ServerControl : MonoBehaviour
{void Start(){UdpManager.InitializeUdpClient();//part1Root.SetActive(true);//part2Root.SetActive(false);}void Update(){if (UdpManager.m_receivedMessage != null){string[] array = UdpManager.m_receivedMessage.Split(',');Debug.Log(UdpManager.m_receivedMessage);UdpManager.m_receivedMessage = null;}}private void OnDestroy(){UdpManager.Close();}
}

使用方法很简单,把ServerControl脚本挂载在一个物体上,直接运行即可,接受信息的方法和发送的方法都在两个脚本里。

http://www.qdjiajiao.com/news/6879.html

相关文章:

  • 网站上可以做收藏按钮吗企业宣传文案
  • 郑州正岩建设集团网站百度怎么推广自己的网站
  • ICP备案和实际网站不是一个名字线下引流的八种推广方式
  • 网站建设人员岗位设置中国广告网
  • 石家庄网站建设成功案例最新的销售平台
  • 广州网站开发定制福州专业的seo软件
  • iis7.5怎么做网站怎么推广软件
  • 做博客网站需要工具吗看广告收益的正规平台
  • 桐城网站定制seo网站推广的主要目的包括
  • 武进做网站怎么做网站卖产品
  • 去哪里找做网站的人百度竞价排名案例分析
  • 查建设公司资质的网站关键词优化 搜索引擎
  • 全国建设建管中心网站长沙seo优化排名
  • 做商城网站建设天津seo排名效果好
  • 嘉兴哪家公司做网站比较好的seo五大经验分享
  • 网站建设有什么工作国际新闻最新消息战争
  • 吉林省建设厅网站市政资质要求上海优化网站方法
  • 做电商怎么建网站有域名和服务器怎么建网站
  • 做网站是什么公司网络暴力事件
  • 石家庄白帽seo网络公司seo门户网站建设方案
  • 阿里云 企业 网站济南做seo的公司排名
  • 招聘网站建设费用多少钱百度爱企查电话人工服务总部
  • 公司网站建设及推广热门网站
  • 织梦音乐网站seo技术培训茂名
  • 做网站导航怎么调整大小最有效的网络推广方式
  • wordpress怎么添加登录界面seo优化点击软件
  • 做视频网站需要哪些手续关键词排名工具
  • 微信微网站建设平台sem网络推广公司
  • 网站制作与网站建设产品推广图片
  • 上海网站建设公司地武汉seo群