예제 #1
0
        public WiFiDeviceGateway(string ovrDeviceHostname, bool scentActivationLogging = false, int localhostDebugPort = 0)
        {
            _socketSender      = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _ovrDeviceHostname = ovrDeviceHostname;
            _socketRecieveState.ovrHostname = _ovrDeviceHostname;
            _socketRecieveState.udpClient   = new UdpClient(0, AddressFamily.InterNetwork);

            var localIp = IPAddressExtensions.GetLocalIP();

            UnityEngine.Debug.LogFormat("<b>[OVR]</b> Local IP: {0}", localIp);

            if (scentActivationLogging)
            {
                _scentActivationLog = new NetworkLogging(localhostDebugPort);
            }

            _socketRecievePort = ((IPEndPoint)_socketRecieveState.udpClient.Client.LocalEndPoint).Port;

            // Setup for broadcasting hostname request from device
            MarshalHeader.Set(ref _checkConnectionPacket, MessageTypes.DEVICE_HOSTNAME_REQUEST, sizeof(ushort));
            _checkConnectionPacket[MarshalHeader.Size]     = (byte)_socketRecievePort;
            _checkConnectionPacket[MarshalHeader.Size + 1] = (byte)(_socketRecievePort >> 8);
            _onConnect    += OnConnect;
            _onDisconnect += OnDisconnect;
        }
예제 #2
0
        public void BeginConnect()
        {
            if (_currentDeviceEndPoint == null)
            {
                _socketSender.EnableBroadcast = true;
                foreach (var address in IPAddressExtensions.GetBroadcastAddresses())
                {
                    _socketSender.SendTo(_checkConnectionPacket, SocketFlags.None, new IPEndPoint(address, _remotePort));
                }

                _socketSender.EnableBroadcast = false;
            }
            else
            {
                // UnityEngine.Debug.LogFormat("<b>[OVR]</b> Device IP: {0}", _currentDeviceEndPoint);
                _socketSender.SendTo(_checkConnectionPacket, _currentDeviceEndPoint);
            }
            _socketRecieveState.udpClient.BeginReceive(ReceiveCallback, _socketRecieveState);
        }