NewN_UAVPlane/Assets/MyNetMQClient.cs

119 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
{
}