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

21天网站建设实录pdfandroid项目开发

21天网站建设实录pdf,android项目开发,凡科快图免费版商用,深圳福田区有哪些企业你想在unity WebGL里面使用TCP通信吗#xff0c;那么你可以用一用webSocket。当然#xff0c;桌面端也可以使用webSocket#xff0c;这样Unity多平台发布的时候#xff0c;业务层的通信代码可以使用一套#xff0c;而不是桌面用socket#xff0c;网页用http… 一、什么是…你想在unity WebGL里面使用TCP通信吗那么你可以用一用webSocket。当然桌面端也可以使用webSocket这样Unity多平台发布的时候业务层的通信代码可以使用一套而不是桌面用socket网页用http… 一、什么是webSocket 顾名思义它就是web版的socket那什么是socket呢… 二、Unity中webSocket相关的包有哪些 endel/NativeWebSocket 项目链接 三、Unity客户端的实现 联网演示 绑定脚本 代码清单 代码来自NativeWebSocket官网demo略作修改 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using NativeWebSocket;public class Connection : MonoBehaviour {WebSocket websocket;public Text textLog;// Start is called before the first frame updateasync void Start(){websocket new WebSocket(ws://192.168.0.146:8081);websocket.OnOpen () {Debug.Log(Connection open!);textLog.text $Connection open! {Time.realtimeSinceStartup} \n {textLog.text};};websocket.OnError (e) {Debug.Log(Error! e);textLog.text $Error:{e} {Time.realtimeSinceStartup} \n {textLog.text};};websocket.OnClose (e) {Debug.Log(Connection closed!);textLog.text $Connection closed! {Time.realtimeSinceStartup} \n {textLog.text};};websocket.OnMessage (bytes) {Debug.Log(OnMessage!);textLog.text $OnMessage! {Time.realtimeSinceStartup} \n {textLog.text};Debug.Log(bytes);// getting the message as a stringvar message System.Text.Encoding.UTF8.GetString(bytes);textLog.text $消息内容{message} {Time.realtimeSinceStartup} \n {textLog.text};//Debug.Log(OnMessage! message);};// Keep sending messages at every 0.3sInvokeRepeating(SendWebSocketMessage, 0.0f, 0.3f);// waiting for messagesawait websocket.Connect();}void Update(){ #if !UNITY_WEBGL || UNITY_EDITORwebsocket.DispatchMessageQueue(); #endif}async void SendWebSocketMessage(){if (websocket.State WebSocketState.Open){// Sending bytesawait websocket.Send(new byte[] { 10, 20, 30 });// Sending plain textawait websocket.SendText(plain text message);}}private async void OnApplicationQuit(){await websocket.Close();}}四、服务端的实现C# WinForm 1、服务器端用到的包 github链接 2、主要代码 代码来自官网Demo略有修改 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Fleck;namespace WinFormsApp1 {public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){var server new WebSocketServer(ws://192.168.0.146:8081); //ws://localhost:8081 ws://127.0.0.0:8181server.Start(socket {socket.OnOpen () {Debug.WriteLine($有新用户连入{socket.ConnectionInfo.ClientIpAddress});};socket.OnClose () {Debug.WriteLine($用户断开连接{socket.ConnectionInfo.ClientIpAddress});};socket.OnMessage message {socket.Send($服务器收到消息 : {DateTime.Now.ToString()});Debug.WriteLine($收到一条消息来自{socket.ConnectionInfo.ClientIpAddress});};});Debug.WriteLine(服务器已经启动);}} }五、客户端的WebGL和Win 桌面测试 桌面和webGL都没问题、这样可以一套代码打天下。 以前用socket在桌面(包括一体头盔)在web端只能用http现在可以统一了。
http://www.hkea.cn/news/14577616/

相关文章:

  • 北京网站设计成功a刻徐州网络推广服务
  • 重庆公司网站 技术支持义乌建设局网站
  • 免费浏览的网站松溪网站建设
  • 计算机课程网站建设实训报告总结wordpress表单信息在哪里
  • 土特产网站建设网站服务器如何做热备价
  • 俄文网站开发网站建设项目实训心得
  • 视频网站做app开发的现在手机网站用什么做的
  • 非专业人士可以做网站编辑的工作吗wordpress子目录建站
  • 万维网站会员管理系统app
  • 黄岛开发区网站制作青岛网站建设设计
  • 网站建设中下载php黄页系统
  • 微信 微网站开发电商平台方案
  • 蝴蝶传媒网站推广四川成都最新消息
  • 韶关微网站建设c 做的网站怎么上传
  • 自己做网站流程微信服务号怎么做商城
  • 福州网站建设 找燕狂徒 04网站建设怎么收费呀
  • 中国公路建设行业协会网站网页特效设计
  • 网站帮助页面设计搜索引擎优化搜索优化
  • 龙华城市建设局网站苏州网站开发公司电话
  • 网站域名到期登不上是怎么回事cnzz统计代码放在网站
  • 水利建设与管理司网站亚马逊网站链接
  • 贵阳市城乡建设厅网站受欢迎的手机网站建设
  • 微信公众平台绑定网站四川网站建设设计公司哪家好
  • 网站数据库到期外链信息
  • 昆明网站建设系统百度广告投放代理商
  • 服务专业公司网站建设服务济南建站公司效果
  • 百度网站推广找谁做关键词挖掘网站
  • 如何网站切换朋友圈转wordpress文章显示缩略图
  • 电子商务网站开发难点中国石油工程建设有限公司网站
  • 网站是专门对生活中的一些所谓常识做辟谣的wordpress获取token方法