Esempio n. 1
0
        // -- Lifecycle functionality

        public void SetupManager(string a_ip, int a_port)
        {
            _managerStatus = UPP_ManagerStatus.CONNECTING;

            try
            {
                // Setup network connection
                switch (Protocol)
                {
                case UPP_PacketProtocol.TCP:
                    twoWaySocket = new UPP_TCP_TwoWaySocket(a_ip, a_port);
                    break;

                default:
                case UPP_PacketProtocol.UDP:
                    twoWaySocket = new UPP_UDP_TwoWaySocket(a_ip, a_port);
                    break;
                }

                twoWaySocket.PacketsSent     = 0;
                twoWaySocket.PacketsReceived = 0;
                // Register callback on packet received
                twoWaySocket.ReceivePacketHook = ReceiveMessage;
            } catch (SocketException e) {
                Debug.LogFormat("Failed to setup UPP Manager {0}: {1}", this.name, e);
            }
            OnSetup.Invoke(this, twoWaySocket);
            _managerStatus = UPP_ManagerStatus.CONNECTED;
        }
Esempio n. 2
0
        public void CloseManager()
        {
            _managerStatus = UPP_ManagerStatus.CLOSING;

            if (twoWaySocket != null)
            {
                twoWaySocket.Close();
            }

            twoWaySocket = null;

            _managerStatus = UPP_ManagerStatus.CLOSED;
        }