Ejemplo n.º 1
0
 public override void Connect(IPAddress address, int port)
 {
     tcpClient = new TcpClient(AddressFamily.InterNetworkV6);
     tcpClient.Client.DualMode = true;
     if (!IPTool.IOSCheck(address, out address))
     {
         address = address.MapToIPv6();
     }
     try
     {
         tcpClient.Connect(address, port);
         if (tcpClient.Connected)
         {
             fireCompleteConnect();
             StartReceiveAsync(tcpClient);
         }
         else
         {
             fireCompleteDisconnect();
         }
     }
     catch (SocketException e)
     {
         switch (e.ErrorCode)
         {
         case (int)SocketError.ConnectionRefused:
             fireCompleteDisconnect();
             LogProxy.WriteLine(e.Message);
             break;
         }
     }
 }
Ejemplo n.º 2
0
 public override void Connect(IPAddress address, int port)
 {
     tcpClient = new TcpClient(AddressFamily.InterNetworkV6);
     tcpClient.Client.DualMode = true;
     if (!IPTool.IOSCheck(address, out address))
     {
         address = address.MapToIPv6();
     }
     tcpClient.BeginConnect(address, port, onCompleteConnect, tcpClient);
 }
Ejemplo n.º 3
0
        public override void Connect(Uri uri)
        {
            IPAddress addr = IPAddress.Parse(uri.Host);

            if (Application.platform != RuntimePlatform.WebGLPlayer)
            {
                if (IPTool.IOSCheck(addr, out addr))
                {
                    string ipv6UriString = string.Format("ws://[{0}]:{1}/WebSocket", addr.ToString(), uri.Port);
                    uri = new Uri(ipv6UriString);
                }
            }

            mWebSocket = new WebSocket(uri);

            mWebSocket.StartPingThread = true;
            mWebSocket.OnOpen         += webSocket =>
            {
                UnityEngine.Debug.Log("WebSocket isOpen= " + webSocket.IsOpen);
                if (webSocket.IsOpen)
                {
                    onCompleteConnect(null);
                }
            };
            mWebSocket.OnBinary += (webSocket, message) =>
            {
                fireCompleteReadFromServerStream(message);
                //UnityEngine.Debug.Log("Binary Message received from server. Length: " + message.Length);
            };
            mWebSocket.OnError += (ws, ex) =>
            {
                string errorMsg = string.Empty;
                fireCompleteDisconnect();
                mWebSocket.Close();
                UnityEngine.Debug.Log("An error occured: " + (ex != null ? ex.Message : "Unknown: " + errorMsg));
                System.Console.WriteLine("MYLOG = Error:" + ex.Message);
            };
            mWebSocket.OnClosed += (webSocket, code, message) =>
            {
                fireCompleteDisconnect();
                UnityEngine.Debug.Log("WebSocket Closed!");
                System.Console.WriteLine("MYLOG = Client Close");
            };
            mWebSocket.Open();
        }
Ejemplo n.º 4
0
        public override void Connect(Uri uri)
        {
            SetFireDisconnectTrigger();
            IPAddress addr = IPAddress.Parse(uri.Host);

            if (Application.platform != RuntimePlatform.WebGLPlayer)
            {
                if (IPTool.IOSCheck(addr, out addr))
                {
                    string ipv6UriString = string.Format("ws://[{0}]:{1}/WebSocket", addr.ToString(), uri.Port);
                    uri = new Uri(ipv6UriString);
                }
            }

            mWebSocket = new WebSocket(uri);

            mWebSocket.StartPingThread = true;
            mWebSocket.OnOpen         += webSocket =>
            {
                LogProxy.WriteLine("WebSocket isOpen= " + webSocket.IsOpen);
                if (webSocket.IsOpen)
                {
                    onCompleteConnect(null);
                }
            };
            mWebSocket.OnBinary += (webSocket, message) =>
            {
                fireCompleteReadFromServerStream(message);
            };
            mWebSocket.OnError += (WebSocket webSocket, Exception ex) =>
            {
                LogProxy.WriteLine("OnError");
                webSocket.Close();
                CheckAndFireDisconnect();
                //Debug.LogError(ex.Message);
            };
            mWebSocket.OnClosed += (webSocket, code, message) =>
            {
                LogProxy.WriteLine("OnClose");
                CheckAndFireDisconnect();
            };
            mWebSocket.Open();
        }
Ejemplo n.º 5
0
        public override void Connect(IPAddress addr, int port)
        {
            LogProxy.WriteLine("<color=darkblue>Udp.Connect=>addr=" + addr + ",port=" + port + "</color>");

            if ((maintainConnecting == null) || !maintainConnecting.Enabled)
            {
                udpClient = new UdpClient(AddressFamily.InterNetworkV6);
                Socket newSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp)
                {
                    DualMode = true
                };
                udpClient.Client = newSocket;

                if (!IPTool.IOSCheck(addr, out addr))
                {
                    addr = addr.MapToIPv6();
                }
                serverIPEndPoint = new IPEndPoint(addr.MapToIPv6(), port);

                udpClient.Send(ReqConnect, ReqConnect.Length, serverIPEndPoint);
                udpClient.BeginReceive(onCompleteConnect, udpClient);
            }
        }