Esempio n. 1
0
        public void JoinRoom(IPEndPoint ipe)
        {
            //if (externalIP.Length == 0) throw new Exception("Can't Get Public Ip address.");
            SignalingClientMessage ssm = new SignalingClientMessage(SignalingMethod.JoinRoomRequest);

            byte[] addressByte = ipe.Address.GetAddressBytes();
            byte[] ip          = new byte[3 + addressByte.Length];
            if (addressByte.Length > 4)
            {
                ip[0] = 0x2;
            }
            else
            {
                ip[0] = 0x1;
            }
            ushort port = (ushort)ipe.Port;

            ip[2] = (byte)(port & 0xff);
            ip[1] = (byte)((port >> 8) & 0xff);
            int idx = 3;

            for (int i = addressByte.Length - 1; i >= 0; i--)
            {
                ip[idx++] = addressByte[i];
            }
            //Array.Copy(addressByte, 0, ip, 3, addressByte.Length);
            ssm.WriteBytes(SignalingAttribute.RoomAddress, ip);
            ssm.WriteString(SignalingAttribute.RoomTag, RoomTag);

            /*addressByte = IPString2Bytes(externalIP);
             * ip = new byte[3 + addressByte.Length];
             * if (addressByte.Length > 4) ip[0] = 0x2;
             * else ip[0] = 0x1;
             * port = (ushort)externalPort;
             * ip[2] = (byte)(port & 0xff);
             * ip[1] = (byte)((port >> 8) & 0xff);
             * //Array.Copy(addressByte2, 0, ip2, 3, addressByte2.Length);
             * idx = 3;
             * for (int i = addressByte.Length - 1; i >= 0; i--)
             *  ip[idx++] = addressByte[i];
             * ssm.WriteBytes(SignalingAttribute.PeerAddress, ip);*/

            sender.Send(ssm.WriteRequest());
        }
Esempio n. 2
0
        public void CreateRoom(IPEndPoint ipe, string roomName, string description)
        {
            SignalingClientMessage ssm = new SignalingClientMessage(SignalingMethod.CreateRoomRequest);

            byte[] addressByte = ipe.Address.GetAddressBytes();
            byte[] ip          = new byte[3 + addressByte.Length];
            if (addressByte.Length > 4)
            {
                ip[0] = 0x2;
            }
            else
            {
                ip[0] = 0x1;
            }
            ushort port = (ushort)ipe.Port;

            ip[2] = (byte)(port & 0xff);
            ip[1] = (byte)((port >> 8) & 0xff);
            int idx = 3;

            for (int i = addressByte.Length - 1; i >= 0; i--)
            {
                ip[idx++] = addressByte[i];
            }
            //Array.Copy(addressByte, 0, ip, 3, addressByte.Length);
            ssm.WriteBytes(SignalingAttribute.RoomAddress, ip);
            ssm.WriteString(SignalingAttribute.RoomTag, RoomTag);
            ssm.WriteString(SignalingAttribute.RoomName, roomName);
            if (description == null || description.Length == 0)
            {
                ssm.WriteEmpty(SignalingAttribute.RoomDescription);
            }
            else
            {
                ssm.WriteString(SignalingAttribute.RoomDescription, description);
            }

            sender.Send(ssm.WriteRequest());
        }