资源简介
这是一个可以发布到HoloLens的socket通信示例,基于Unity5.3.4f1编写的,发布到HoloLens绝对没问题的,你可以根据自己需求自行修改。

代码片段和文件信息
/**
* 版本:0.01
* 作者:吴雁涛
* 日期:2016年4月29日
* 内容:服务器端客户端通信学习
*
**/
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using System;
public class MyNetworkManager : MonoBehaviour
{
///
/// 服务器ip地址
///
public InputField ip;
///
/// 服务器端口
///
public InputField port;
///
/// 要发送的信息
///
public InputField send;
///
/// 显示信息
///
public Text info;
///
/// 网络客户端
///
private NetworkClient myClient;
///
/// 用户信息分类
///
private const short userMsg = 64;
void Start ()
{
info.text = “Start...“;
myClient = new NetworkClient ();
}
///
/// 建立服务器
///
public void SetupServer ()
{
if (!NetworkServer.active) {
ShowMsg (“setup server“);
ServerRegisterHandler ();
NetworkServer.Listen (int.Parse (port.text));
if (NetworkServer.active) {
ShowMsg (“Server setup ok.“);
}
}
}
///
/// 建立客户端
///
public void SetupClient ()
{
if (!myClient.isConnected) {
ShowMsg (“setup client“);
ClientRegisterHandler ();
myClient.Connect (ip.text int.Parse (port.text));
}
}
///
/// 停止客户端
///
public void ShutdownClient ()
{
if (myClient.isConnected) {
ClientUnregisterHandler ();
myClient.Disconnect ();
//NetworkClient.Shutdown()使用后,无法再次连接。
//This should be done when a client is no longer going to be used.
//myClient.Shutdown ();
}
}
///
/// 停止服务器端
///
public void ShutdownServer ()
{
if (NetworkServer.active) {
ServerUnregisterHandler ();
NetworkServer.DisconnectAll ();
NetworkServer.Shutdown ();
if (!NetworkServer.active) {
ShowMsg (“shut down server“);
}
}
}
///
/// 客户端连接到服务器事件
///
/// Net message.
private void OnClientConnected (NetworkMessage netMsg)
{
ShowMsg (“Client connected to server“);
}
///
///客户端从服务器断开事件
///
/// Net message.
private void OnClientDisconnected (NetworkMessage netMsg)
{
ShowMsg (“Client disconnected from server“);
}
///
/// 客户端错误事件
///
/// Net message.
private void OnClientError (NetworkMessage netMsg)
{
ClientUnregisterHandler ();
ShowMsg (“Client error“);
}
///
/// 服务器端有客户端连入事件
///
/// Net message.
private void OnServerConnected (NetworkMessage netMsg)
{
ShowMsg (“One client connected to server“);
}
///
/// 服务器端有客户端断开事件
///
/// Net message.
private void OnServerDisconnected (NetworkMessage netMsg)
{
ShowMsg (“One client connected from server“);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 14435 2016-04-27 10:25 HololensSocketDemo\Assembly-CSharp-Editor.csproj
文件 4304 2016-04-28 09:22 HololensSocketDemo\Assembly-CSharp-firstpass.csproj
文件 4188 2016-04-29 14:11 HololensSocketDemo\Assembly-CSharp.csproj
文件 6246 2016-04-29 15:05 HololensSocketDemo\Assets\MyNetworkManager.cs
..A..H. 263 2016-04-28 17:51 HololensSocketDemo\Assets\MyNetworkManager.cs.me
文件 721 2016-04-28 17:56 HololensSocketDemo\Assets\NWLearn.cs
..A..H. 263 2016-04-28 17:40 HololensSocketDemo\Assets\NWLearn.cs.me
I.A.... 4908 2016-04-28 17:39 HololensSocketDemo\Assets\play.prefab
..A..H. 180 2016-04-28 17:39 HololensSocketDemo\Assets\play.prefab.me
I.A.... 38872 2016-04-28 17:57 HololensSocketDemo\Assets\server.unity
..A..H. 175 2016-04-28 17:38 HololensSocketDemo\Assets\server.unity.me
I.A.... 4120 2016-04-19 15:10 HololensSocketDemo\Library\AnnotationManager
I.A.... 1546436 2016-04-29 15:05 HololensSocketDemo\Library\assetDataba
I.A.... 17 2016-04-29 14:11 HololensSocketDemo\Library\AssetImportState
I.A.... 4756 2016-04-29 15:05 HololensSocketDemo\Library\AssetServerCacheV3
I.A.... 14336 2016-04-20 10:02 HololensSocketDemo\Library\AssetVersioning.db
I.A.... 267700 2016-04-25 10:54 HololensSocketDemo\Library\AtlasCache\11\111396342696616dd8dd8b995bde38c9
I.A.... 8596 2016-04-25 10:54 HololensSocketDemo\Library\AtlasCache\58\58dc768eb225cb597fc603bc9cc9ceca
I.A.... 5860 2016-04-25 10:54 HololensSocketDemo\Library\AtlasCache\79\79d17962e46a00b8a8886503a748da94
I.A.... 11195052 2016-04-25 10:54 HololensSocketDemo\Library\AtlasCache\a2\a2f82126fda7305f2a23618ab2749eba
I.A.... 0 2016-04-19 15:10 HololensSocketDemo\Library\BuildPla
I.A.... 4128 2016-04-19 15:10 HololensSocketDemo\Library\BuildSettings.asset
I.A.... 40260 2016-04-29 15:05 HololensSocketDemo\Library\CurrentLayout.dwlt
I.A.... 4341 2016-04-29 14:11 HololensSocketDemo\Library\EditorUserBuildSettings.asset
I.A.... 4148 2016-04-19 15:10 HololensSocketDemo\Library\EditorUserSettings.asset
I.A.... 4464 2016-04-29 15:05 HololensSocketDemo\Library\expandedItems
I.A.... 4544 2016-04-28 15:41 HololensSocketDemo\Library\InspectorExpandedItems.asset
文件 78 2016-04-29 15:05 HololensSocketDemo\Library\LastSceneManagerSetup.txt
文件 65 2016-04-19 15:10 HololensSocketDemo\Library\LibraryFormatVersion.txt
I.A.... 4285 2016-04-19 15:10 HololensSocketDemo\Library\me
............此处省略2125个文件信息
相关资源
- Borland Socket Server Fix2.0 D7
- Borland Socket Server程序 包含D6和D7源码
- 通信软件的具体实例──基于Socket的
- 用Socket编程实现FTP
- websocket实现一对一聊天
- Unity3D登录界面工程
- unity3d反编译工具
- 代码客:G-TcpServer(IOCP) 1.0 正式版及
- SOCKET 网络编程 计算机网络 作业 客户
- linux 网络实验 ftp程序
- 用Socket写的简易FTP服务器和客户端
- socket小工具(可方便建立TCP UDP的soc
- socket客户端源码
- 基于CSocket的多人聊天室
- socket文件传输源码
-
UnityWebPla
yer及UnityWebPla yerFull -
UnityWebPla
yerFull - Socket自制系统
- HP用SOCKET实现(客户端---服务端)
- unity4.0官方正式版
- zeromq的windows版本安装包
- Behavior Designer 1.6.3(u2018.3.0).unitypa
- Unity纪念碑谷.rar
- A Pathfinding Project Pro v4.2.2.rar
- Unity 声音播放插件,支持将字符串转
- Gaia 1.7.2
- STM32分别以串口硬件SPI模拟并口驱动
- Unity3d实现扭动挤压浏览效果
- UnityShader卷轴效果
- 爱酱(绊爱Kizuna)模型
评论
共有 条评论