Beispiel #1
0
    public void OnGUI()
    {
        GUILayout.BeginVertical();
        if (GUILayout.Button("Connect", GUILayout.Width(200)))
        {
            m_TChannel = (TChannel)m_TService.ConnectChannel(NetHelper.ToIPEndPoint("127.0.0.1", 2500));
        }

        if (GUILayout.Button("Send", GUILayout.Width(200)))
        {
            using (var mem = new MemoryStream())
            {
                var word_byts = Encoding.UTF8.GetBytes("Hello Udp!");
                mem.Write(word_byts, 0, word_byts.Length);
                mem.Position = 0;
                m_TChannel.Send(mem);
            }
        }

        if (GUILayout.Button("DisConnect", GUILayout.Width(200)))
        {
            m_TChannel.DisConnect();
        }
        if (GUILayout.Button("Dispose", GUILayout.Width(200)))
        {
            m_TChannel.Dispose();
        }
        GUILayout.EndVertical();
    }
Beispiel #2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        private NetworkManager()
        {
            service = new TService(packetSizeLength: 2);
            var channel = service.ConnectChannel("127.0.0.1:55555");

            session = new Session();
            session.Awake(channel);
            session.Start();
            session.OnReadCallBack += OnRead;
        }