Exemplo n.º 1
0
        public void WP8TcpClientBeginEndConnect_ValidIP_Succeed()
#endif
        {
            bool   success = false;
            string error   = String.Empty;

            try
            {
                TcpClient            tcpClient = new TcpClient();
                TaskStateAsyncResult ar        = (TaskStateAsyncResult)tcpClient.BeginConnect("127.0.0.1", 80, null, null);

                while (!ar.IsCompleted)
                {
                    ;
                }

                tcpClient.EndConnect(ar);
                success = true;
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            Assert.IsTrue(success, error);
        }
Exemplo n.º 2
0
        public void WP8TcpClientBeginEndConnect_InvalidIP_Fail()
#endif
        {
            bool   success = false;
            string error   = String.Empty;

            try
            {
                TcpClient            tcpClient = new TcpClient();
                TaskStateAsyncResult ar        = (TaskStateAsyncResult)tcpClient.BeginConnect(null, 80, null, null);

                while (!ar.IsCompleted)
                {
                    ;
                }

                tcpClient.EndConnect(ar);
                success = true;
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            Assert.IsFalse(success, "Should fail with invalid IP.");
        }
Exemplo n.º 3
0
        public static IAsyncResult BeginRead(this Stream stream, byte[] buffer, int offset, int count, AsyncCallback callback, object state = null)
        {
#if NETFX_CORE
            var task = stream.ReadAsync(buffer, offset, count);
            var ar   = new TaskStateAsyncResult <int>(task, state);
            if (callback != null)
            {
                task.ContinueWith((t) =>
                {
                    callback(ar);
                });
            }
            return(ar);
#else
            throw new PlatformNotSupportedException("Stream.BeginRead");
#endif
        }
        public IAsyncResult BeginConnect(string host, int port, AsyncCallback requestCallback, object state)
        {
#if NETFX_CORE
            var task = EnsureSocket(host, port);
            TaskStateAsyncResult res = new TaskStateAsyncResult(task, state);

            task.ContinueWith((t) =>
            {
                if (requestCallback != null)
                {
                    requestCallback(res);
                }
            });

            return(res);
#else
            throw new PlatformNotSupportedException();
#endif
        }
Exemplo n.º 5
0
        public static IAsyncResult BeginGetHostEntry(string remoteHostName, AsyncCallback requestCallback, Object stateObject)
        {
#if NETFX_CORE
            var task = ResolveDNS(remoteHostName);
            TaskStateAsyncResult <string> res = new TaskStateAsyncResult <string>(task, stateObject);

            task.ContinueWith((t) =>
            {
                if (requestCallback != null)
                {
                    requestCallback(res);
                }
            });

            return(res);
#else
            throw new PlatformNotSupportedException();
#endif
        }