Exemplo n.º 1
0
        public FastConnection(string remotehost, int remoteport, IRTSessionInternal session) : base(remotehost, remoteport, session)
        {
#if __WINDOWS__
            client = new DatagramSocket();
            client.MessageReceived += OnSocketMessageReceived;

            Task t = Task.Run(() => {
                ConnectAsync().Wait();

                DoLogin();
            });

            session.Log("FastConnection", GameSparksRT.LogLevel.DEBUG, " local=" + endPoint.LocalHostName + " remote=" + remotehost + ":" + remoteport);
#else
            bool ipv6 = false;

            callback = new AsyncCallback(Recv);

            if (remoteEndPoint.AddressFamily == AddressFamily.InterNetworkV6)
            {
                try {
                    if (Socket.OSSupportsIPv6)
                    {
                        ipv6 = true;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Socket.OSSupportsIPv6: " + e.ToString());
                }

                try {
                    if (Socket.SupportsIPv6)
                    {
                        ipv6 = true;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Socket.SupportsIPv6: " + e.ToString());
                }
            }

            if (ipv6)
            {
                client = new UdpClient(AddressFamily.InterNetworkV6);

                Console.WriteLine("IPv6 on!");
            }
            else
            {
                client = new UdpClient(AddressFamily.InterNetwork);
            }

            client.Connect(remoteEndPoint);

            session.Log("FastConnection", GameSparksRT.LogLevel.DEBUG, " local=" + client.Client.LocalEndPoint + " remote=" + remotehost + ":" + remoteport);

            client.Client.BeginReceive(buffer, 0, GameSparksRT.MAX_UNRELIABLE_MESSAGE_SIZE_BYTES, 0, callback, null);

            DoLogin();
#endif
        }
Exemplo n.º 2
0
        public ReliableWSConnection(string remotehost, int remoteport, IRTSessionInternal session) : base(remotehost, remoteport, session)
        {
            //GameSparks.Core.GameSparksUtil.LogMessageHandler = Console.WriteLine;

            session.Log("ReliableWSConnection", GameSparksRT.LogLevel.DEBUG, "wss://" + remotehost + ":" + remoteport);

            if (session.GetGSInstance() != null)
            {
                socket = session.GetGSInstance().GSPlatform.GetBinarySocket("wss://" + remotehost + ":" + remoteport, OnBinaryMessageReceived, OnClosed, OnOpened, OnError);
            }
            else
            {
                socket = new GameSparksWebSocket();
                socket.Initialize("wss://" + remotehost + ":" + remoteport, OnBinaryMessageReceived, OnClosed, OnOpened, OnError);
            }
            socket.Open();
        }