119 lines
2.6 KiB
C#
119 lines
2.6 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using System;
|
||
using System.Collections.Concurrent;
|
||
using System.Linq;
|
||
using System.Diagnostics;
|
||
using UnityEngine.Networking;
|
||
using System.Net;
|
||
using System.Net.Sockets;
|
||
using System.Text;
|
||
using System.Threading;
|
||
|
||
public class MyNetMQClient : MonoBehaviour
|
||
{
|
||
public static MyNetMQClient instance;
|
||
[DisplayOnly]
|
||
public string PubIP= "127.0.0.1:8082";
|
||
[DisplayOnly]
|
||
public string SubIP = "127.0.0.1:8081";
|
||
|
||
/// <summary>
|
||
/// 接口IP (配置文件)
|
||
/// </summary>
|
||
public static string CallIP = "192.168.1.161:8080";
|
||
public static string SyncServerIP = "192.168.1.161:8888";
|
||
public static string remoteServerIP = "192.168.1.161:8890";
|
||
|
||
[HideInInspector]
|
||
public NetMqListener _netMqListener;
|
||
[HideInInspector]
|
||
public NetMqPublisher _netMqPublisher;
|
||
|
||
|
||
|
||
private void Awake()
|
||
{
|
||
instance = this;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始化Netmq
|
||
/// </summary>
|
||
/// <param name="reciveInMono">接收函数</param>
|
||
public void Init(string ServerSubIP,string ServerPubIP, NetMqListener.ReciveMessageInThread reciveInthread, NetMqListener.ReceiceMessageInMono reciveInMono,string typename)
|
||
{
|
||
SubIP = ServerSubIP;
|
||
PubIP = ServerPubIP;
|
||
//开启接收模块
|
||
_netMqListener = new NetMqListener(ServerSubIP, reciveInthread, reciveInMono);
|
||
_netMqListener.typeName = typename;
|
||
//开启发送模块
|
||
_netMqPublisher = new NetMqPublisher(ServerPubIP);
|
||
_netMqPublisher.typeName = typename;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 发送消息
|
||
/// </summary>
|
||
/// <param name="msg"></param>
|
||
public void Send(string msg)
|
||
{
|
||
_netMqPublisher.AddMessageToSendQue(GlobalFlag.roomID, 0, Encoding.UTF8.GetBytes(msg));
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (_netMqListener != null)
|
||
{
|
||
_netMqListener.UpdateByte();
|
||
}
|
||
}
|
||
|
||
public void Destroy()
|
||
{
|
||
_netMqListener._listenerCancelled = true;
|
||
_netMqPublisher._listenerCancelled = true;
|
||
UnityEngine.Debug.Log("销毁xxxxx");
|
||
Destroy(this);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 消息体
|
||
/// </summary>
|
||
[Serializable]
|
||
public class st_Motions
|
||
{
|
||
/// <summary>
|
||
/// 域
|
||
/// </summary>
|
||
public string area;
|
||
/// <summary>
|
||
/// 消息标识
|
||
/// </summary>
|
||
public int m_iOperaType;
|
||
/// <summary>
|
||
/// 消息内容(byte[256])
|
||
/// </summary>
|
||
public byte[] m_sOperaData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 演习状态
|
||
/// </summary>
|
||
public enum ProgramState
|
||
{
|
||
结束,
|
||
进行中
|
||
}
|
||
|
||
public class DisplayOnly : PropertyAttribute
|
||
{
|
||
|
||
} |