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); }
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."); }
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 }
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 }